[Python-de] while(!eof) in Python??
Det
ddet at gmx.de
Thu Apr 25 22:15:06 EDT 2002
On Thu, Apr 25, 2002 at 12:25:02PM +0200, Janko Hauser wrote:
> On Thu, 25 Apr 2002 10:25:04 +0200 (MEST)
> Erhan_A at gmx.de wrote:
>
> > mal ne ganz "dumme" Python-Anfängerfrage:
> > wie kann ich in Python, die in anderen Sprachen bekannte
> > while(!eof)-Schleife, darstellen.Muss ich dafür eine Funktion
> > "basteln" oder gibt es dafür eine Python-Darstellung.
> >
>
> fh=open('file','r')
> while 1:
> line = fh.readline()
> if not line:
> break
> ... process line
Hmmm. Was ist mit:
for line in open('file', 'r').readlines():
process line
Viele Gruesse
Dirk Detering -aka Det
More information about the Python-de
mailing list