newbie question...

Eugene Goodrich bitbucket at isomedia.com
Wed Dec 29 13:41:54 EST 1999


How did you know I learned my Python while at Microsoft?

I don't know why I tend to shy away from the while (1): in what I
consider "simple" cases.  I use it plenty in larger loops.

My inclusion of unnecessary parameters in some places comes from not
always  knowing the defaults and a desire to help out some of the less
clueless readers of my code - like me 60 days after I write it :)

And am I making enemies of you all with my silly variable names (the
trashed-hungarian notation)?  That comes from 2 years (I wish it had
been less) of being forced to do ASP with VBScript.  I didn't feel I
could trust the VBScript interpreter to do a thing right for me with
the types.

Thanks for the clue to use while (1) on the file reading.  Jeez, I
can't believe I've been using that lame prep code for so long.  Gotta
lay off the crack.

    -Eugene

On Wed, 29 Dec 1999 12:53:12 +0100, "Fredrik Lundh"
<fredrik at pythonware.com> wrote:

>Eugene Goodrich <bitbucket at isomedia.com> wrote:
>> 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()
>
>is that microsoft python? ;-)
>
>fwiw, the standard pydiom (at least as long
>as we're talking 1.5.2) is:
>
>    f = open('delme.txt') # rt is default
>    while 1:
>        s = f.readline()
>        if not s:
>            break
>        # do something
>
>> Someone please correct me if this does not have the reduced memory
>> requirements for large files that I believe it does.
>
>for a better speed/memory tradeoff, you
>can use "readlines" in the following way:
>
>    f = open('delme.txt')
>    while 1:
>        lines = f.readlines(100000)
>        if not lines:
>            break
>        for s in lines:
>            # do something
>
>also see the fileinput module.
>
></F>
>
><!-- (the eff-bot guide to) the standard python library:
>http://www.pythonware.com/people/fredrik/librarybook.htm
>-->
>
>    "Get into a rut early: Do the same processes the
>    same way. Accumulate idioms. Standardize. The
>    only difference between Shakespeare and you
>    was the size of his idiom list - not the size of his
>    vocabulary." -- Alan Perlis
>
>

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



More information about the Python-list mailing list