how do you know if open failed?
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Thu Sep 28 15:23:25 EDT 2006
More information about the Python-list mailing list
Thu Sep 28 15:23:25 EDT 2006
- Previous message (by thread): how do you know if open failed?
- Next message (by thread): how do you know if open failed?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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, "Failed to open 'noexists' : %s" % e
- Previous message (by thread): how do you know if open failed?
- Next message (by thread): how do you know if open failed?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list