Python learner. So please excuse me.
I am following: http://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files
I want to read a file; here is my file:
# cat test
line1 word1
line2 word2
line3 word3
line4 word4
and here it my code:
>>> f = open ('test')
>>> for line in f:
... print f
...
<open file 'test', mode 'r' at 0xb7729180>
<open file 'test', mode 'r' at 0xb7729180>
<open file 'test', mode 'r' at 0xb7729180>
<open file 'test', mode 'r' at 0xb7729180>
How and why i am getting above output? I was hoping that it will print each line per line.
What am I missing here. looking at the link mentioned above, my syntax seems to be OK but the output is not
Thanks.
You are printing the file handle, replace print f with print line: