Handling errors in open

Paul Magwene paul.magwene at yale.edu
Mon Apr 17 16:23:12 EDT 2000


Jacek Generowicz wrote:
> 
> Hi,
> 
> Is there a way to prevent a Python script from
> terminating when `open' fails, and have it handle
> the error more helpfully . . . I was thinking
> along these lines:
> 
> from sys import argv
> 
> try:
>     file = open(argv[1],"r")
> except IOerror:
>     print "You lied about that file."
> 
> Jacek


Yes, that works...? (slightly confused because you seem to have found
your own answer, yet you still posted the question.  Are you looking for
alternative ways to do this?)

--Paul



More information about the Python-list mailing list