file rewind?

joel8bit jwickard**nospam** at litriusgroup.com
Fri Apr 5 09:02:34 EST 2002


I have this code:

def countLines(file):
    numLines = 0
    for line in file.readlines():
        print line
        numLines = numLines + 1

    print numLines

def countChars(file):
    numChars = 0
    for line in file.readlines():
        print line
        for char in line:
            print char
            numChars += 1
    print numChars

def test(name):
    file = open(name, "r")
    countLines(file)
    countChars(file)

if __name__ == "__main__":
    test("C:\\test.txt")

when I run the module from the comman line by itself, it counts the lines
alright, but does not count the characters.  do I need to "rewind" the file
reference after the first function call to countLines()?





More information about the Python-list mailing list