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, "
"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
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:
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-
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://
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