newbie question...
Justin Sheehy
dworkin at ccs.neu.edu
Tue Dec 28 15:48:08 EST 1999
Alexander Sendzimir <sendzimir at earthlink.net> writes:
> the following Perl construct is pretty standard.
>
> while ( <SOMEFILEHANDLE> )
> {
> # process each line as if comes off the file handle...
> }
Yep.
> 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
If you want to be more succint and not mess around with temporary
variables, you could do:
for line in open('some/file/name.text').readlines():
# process each line...
-Justin
More information about the Python-list
mailing list