[Tutor] output question
samrobertsmith at gmail.com
Sun Nov 13 05:21:03 CET 2005
On 11/12/05, Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote:
> > > > from the code:
> > > > try:
> > > > fsock = open("c:/TEMP/hello.txt")
> > > > except IOError:
> > > > print "The file does not exist, exiting gracefully"
> > > > print "Yes!!! This line will always print"
> > I thought if the except situation does not happen, that means the try
> > section works. At that time, I was a little confused that since the open
> > statement works, why there is nothing showing. Now i know if i want to
> > see a file's content on the screen, open statement is not enough.
> Hi Shi Mu,
> Ok, that sounds good. I second Alan's recommendation to go through his
> tutorial; it'll probably help introduce you to more of the programming
> constructs that you're not familiar with yet.
> One of the things that we all need to work on is identifying presumptions
> and figuring out how to recognize when those assumptions aren't being
> followed. If it looks like a function like open() doesn't do what you
> expect, it's a good idea to double check a tutorial that introduces that
> function, just to see if it's the assumption that needs revision. Are you
> going through a tutorial now?
> By the way, the exception handling above is probably not necessary; it's
> probably ok to start with:
> fsock = open("c:/TEMP/hello.txt")
> without the explicit exception handling. If it fails, it will fail
> gracefully with good debugging output anyway. If you're going to handle
> an exception by exiting, just let the exception escape out: it'll usually
> maintain very useful information like the stack trace.
> Best of wishes!
Thanks a lot for your advice! i am reading the tutorial
More information about the Tutor