while(s=infile.readline()): # reading input

Angus MacKay amackay at starvision.com
Mon Jun 21 16:56:02 EDT 1999


why can't I have syntax like this?
python is written in C after all isn't it?

this works fine:
  while infile.readline():
    print "Hi!"

this doe not:
  while s = infile.readline():
    print s

which is okay, but alas this does not work:
  while(s=infile.readline()):
    print s

is there any way to avoid using the ugly:
  while 1:
    s = infile.readline()
    if not s: break
    print s

cheers, Angus.




More information about the Python-list mailing list