[Tutor] Opening files?

jlohman@cox.net jlohman@cox.net
Wed Mar 26 20:45:03 2003


Ok...I've taken everyone's advice, and it STILL did not work, though there were no syntax errors...hmmmm...

This was the orginal puzzle:

>>> myTest = open("C:test.txt", 'r')
>>> for eachLine in myTest:
... 	print eachLine
...
>>> myTest.close()
>>>

 things were read, but nothing printed.

Now, I decided to break it down. I enter(">>>" is the prompt that the IDLE "Python Shell" gives me):

>>> myTest = open("C:/test.txt", 'r')

It runs.I get a prompt, so I enter:

>>> for eachLine in myTest:
   print eachLine

It goes to the next line, no ">>>" just a blinking cursor, and only when I hit ENTER again, do I get the text from my file. Furthermore, it took me a bit of tweaking and trying just to get the above command to give me what I want.

Now, I am a total novice to Python, and advice may have been given making the assumptions that certain basics of syntax were done. They are not<g>. It appears there are levels of indentaion and carriage-returns that are not totally obvious from examples and CERTAINLY do not cut-and-paste well from examples given in the documanetaion I've found.

I use notepad to write and then paste that into the IDLE "Python Shell". Is there some basic TAB or SPACE or ... or >>> or anything that i am missing to get these programs to line up right? Is Python always this touchy about whitspace and indentations?

Is there soem documentaion somewhere about this, or an editor/compliler that is more forgiving about indentaion s and blocks?

-Jeff