what is wrong with this line? while (line = workfile.readline ()) != "":

Simon Brunning SBrunning at trisystems.co.uk
Tue May 22 11:45:26 EDT 2001


> From:	erudite [SMTP:ask at me.com]
>     I'm coming from the Java world to the python world which is probably
> why
> I'm a little confused as to why this statement doesn't work:
> 
> while (line = workfile.readline()) != "":
> 
> when I try to run it I get a :
> 
>   File "srns.py", line 38
>     while (line = workfile.readline()) != "":
>                 ^
> SyntaxError: invalid syntax
 
In Python, expressions do not return values. The usual Python idiom for this
is:

while 1:
    line = workfile.readline()
    if not line:
        break
    # Process line

See <http://w1.132.telia.com/~u13208596/guides/readline-performance.htm> for
details.

Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning at trisystems.co.uk




-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.




More information about the Python-list mailing list