[Tutor] output question
samrobertsmith at gmail.com
Sun Nov 13 04:33:15 CET 2005
On 11/12/05, Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote:
> > > So, you're successfull opening a file. Now, you need to read it
> > >
> > > for line in fsock:
> > > print line
> > >
> > > Have a play with those.
> > it works! thanks!
> Hi Shi Mu,
> Ok, but let's go back to your original question now, just to make sure
> we've learned something. You asked earlier:
> > 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"
> > it means the code found there is hello.txt, why it does not show on the
> > output.
> Do you know now why the original code didn't do what you want? Can you
> explain why? I know it's seems like a silly question, but we are trying
> to avoid a cargo-cult attitude here. What knowledge did you learn?
> Again, I'm really not getting any sense whatsoever of knowing why you had
> difficulty here. Personally, if I run into difficulty with a problem,
> even if I hack out something that "works", I'm not satisified until I
> understand the reasons why I got stuck. I've been bitten too many times
> by being satisifed by the "right" answer for the wrong reasons. *grin*
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
More information about the Tutor