Re: how do you know if open failed?

2006-09-28 Thread Bruno Desthuilliers
tobiah a écrit : > SpreadTooThin wrote: > >> f = open('myfile.bin', 'rb') >> >> How do I know if there was an error opening my file? >> > try: > open('noexist') > except: > print "Didn't open" > Should be: try: f = open('noexists') except IOError, e: print >> sys.stderr, "

Re: how do you know if open failed?

2006-09-28 Thread Erik Johnson
"tobiah" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > SpreadTooThin wrote: > > f = open('myfile.bin', 'rb') > > > > How do I know if there was an error opening my file? > > > try: > open('noexist') > except: > print "Didn't open" That's a way to trap any exc

Re: how do you know if open failed?

2006-09-28 Thread Neil Cerutti
On 2006-09-28, SpreadTooThin <[EMAIL PROTECTED]> wrote: > f = open('myfile.bin', 'rb') > > How do I know if there was an error opening my file? Try it an see. Seriously, it will raise an exception that you can catch. try: f = open('myfile.bin', 'rb') # Do stuff with f except IOError, inst:

Re: how do you know if open failed?

2006-09-28 Thread tobiah
SpreadTooThin wrote: > f = open('myfile.bin', 'rb') > > How do I know if there was an error opening my file? > try: open('noexist') except: print "Didn't open" -- Posted via a free Usenet account from http://www.teranews.com -- http://mail.python.org/mailman/listinfo/python-

Re: how do you know if open failed?

2006-09-28 Thread Fredrik Lundh
SpreadTooThin wrote: > f = open('myfile.bin', 'rb') > > How do I know if there was an error opening my file? you'll notice: >>> f = open("myfile.bin", "rb") Traceback (most recent call last): File "", line 1, in IOError: [Errno 2] No such file or directory: 'myfile.bin' >>> -- http://

how do you know if open failed?

2006-09-28 Thread SpreadTooThin
f = open('myfile.bin', 'rb') How do I know if there was an error opening my file? -- http://mail.python.org/mailman/listinfo/python-list