File IO.
Jc
jciber16 at hotpop.com
Thu Jan 2 17:56:17 EST 2003
Thanks! I was wondering if I had to use just except IOError and not some
mile long command.
"Raymond Hettinger" <vze4rx4y at verizon.net> wrote in message
news:S3SQ9.49943$ac.2076 at nwrddc01.gnilink.net...
> "Jc" <jciber16 at hotpop.com> wrote in message
> news:3e13e820_4 at corp.newsgroups.com...
> > I'm writing a program and when it can't open a txt file it crashes. How
> can
> > I get it to report the file not being there? I set it up using the basic
> > command,
> >
> > in_file = open(filename+".txt","r")
> > text = in_file.read()
> > in_file.close()
> >
> > Thanks.
> >
> > JC
>
> Wrap the call in a try/except block:
>
> try:
> open('nothere.txt')
> except IOError:
> print 'Cannon open file'
>
>
> Raymond Hettinger
>
>
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
More information about the Python-list
mailing list