[Python-de] while(!eof) in Python??
Janko Hauser
jh at comunit.de
Thu Apr 25 13:25:02 EDT 2002
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
Das oder so aehnlich ist das alte Idiom
Ab Python 2.2 geht
for line in open('file','r'):
process line
HTH,
__Janko
--
i.A. Dr. Janko Hauser
Software Engineering
c o m . u n i t G m b H
online-schmiede seit 1994
http://www.comunit.de/ mailto:jh at comunit.de
Eiffestr. 598 20537 Hamburg | Germany
Fon 040 | 21 11 05 25 Fax 040 | 21 11 05 26
More information about the Python-de
mailing list