newbie question...

Eugene Goodrich bitbucket at isomedia.com
Tue Dec 28 16:30:08 EST 1999


The example Justin Sheehy gave is certainly better most of the time,
but if you feel you _must_ do it like that Perl code (say, you've got
a 100 MB file you don't feel like putting into memory all at once),
you can do this:

	oFile = open ('delme.txt', 'r')
	sStr = oFile.readline()
	while (sStr):
		# do something with sStr
		sStr = oFile.readline ()
	oFile.close()

Someone please correct me if this does not have the reduced memory
requirements for large files that I believe it does.

-Eugene

On Tue, 28 Dec 1999 15:50:35 -0500, Alexander Sendzimir
<sendzimir at earthlink.net> wrote:

>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
>
>
>

import binascii; print binascii.a2b_base64 ('ZXVnZW5lQGlzb21lZGlhLmNvbQ==')



More information about the Python-list mailing list