Newbie Needs help!!

Bryano bryano at noemail.com
Fri Oct 10 13:07:41 EDT 2003


Hi,

I am new to the world of Python and am currently taking my first steps and
have already hit a brick wall, here is my example code:

-------------------------------------------------------------------
#!/usr/bin/python
import sys
import os
import string
import math

InFile = file("testfile","r")             'In my code I have the full file
path to the file
FileCon  = InFile.read()
FileLines = InFile.readline()
print FileCon
print FileLines
InFile.close()

--------------------------------------------------------------------

My testfile contains 2 lines of text i.e

I am Line 1
I am Line 2

What I expect this to show when run is the following:

I am Line 1
I am Line 2
2

However it omits the number of lines in this case 2 ( which i get using the
line FileLines = InFile.readline() )
it would appear that by referencing InFile once that it clears out its
contents so null is always returned when
calling the readline().  If I omit the line that starts FileCon (and
associated print line) it prints the file length correctly as 2.

Any ideas as to why this is happening?? its driving me crazy at the
moment...

Any help appreciated.

Cheers

Rigga




More information about the Python-list mailing list