how do you know if open failed?

Fredrik Lundh fredrik at pythonware.com
Thu Sep 28 14:26:15 EDT 2006


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 "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory: 'myfile.bin'
 >>>

</F>




More information about the Python-list mailing list