newbie question...

Alexander Sendzimir sendzimir at earthlink.net
Tue Dec 28 15:50:35 EST 1999


As a developer new to the Python language and experienced with the Perl language
(and quite a few others ;-), I'm wondering what the accepted method of handling
a text file's contents are in Python. For example, the following Perl construct
is pretty standard.

    while ( <SOMEFILEHANDLE> )
    {
        # process each line as if comes off the file handle...
    }

is typical.

The equivalent Python appears to be

    somefilehandle = open( "some/file/name.text" )
    all_the_lines_in_the_file = somefilehandle.readlines()
    somefilehandle.close()

    # now process the lines in the all_the_lines_... list
    # using some prefered method (there's more than
    # one way of doing this, of course ;-)

THE BIG QUESTION: Am I understanding Python's philosophy properly?

Thanks,

abs






More information about the Python-list mailing list