iterating over lines in a file
Moshe Zadka
moshez at math.huji.ac.il
Thu Jul 20 02:39:05 EDT 2000
On Wed, 19 Jul 2000, nobody wrote:
> this doesn't seem to have a simple, direct analog in python. searching
> around on the web i found a solution at faqts.com (though this newbie
> might like to see it explained, but whatever works):
>
> class Reader:
> def __init__(self, source):
> self.source = source
> def readline(self):
> line = self.source.readline()
> self.line = line
> return line # may be empty, thus false
>
Just put the class in a module you write, and use it everywhere
> now, this seems to me like an awful lot of typing just to get around
> the fact that assignments in python do not seem to be expressions
> returning the value assigned. since that is thus in several other
> languages, and since it gives rise to several common idioms of this
> type, i can only assume that there must be some good reason for
> breaking this pattern in python; i just can't see what it could
> possibly be.
Preventing world war III, when Python achieves world domination.
If C is allowed to achieve world domination, WWIII will be cause by
if(everything_is_ok = 0) {
launch_missile();
}
Whereas since Python wwill achieve world domination,
if everything_is_ok = 0:
launch_missile()
Is a syntax error, and wil be detected before it is allowed into the
automated defense system.
--
Moshe Zadka <moshez at math.huji.ac.il>
There is no GOD but Python, and HTTP is its prophet.
http://advogato.org/person/moshez
More information about the Python-list
mailing list