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

Simon Brunning SBrunning at trisystems.co.uk
Tue May 22 12:17:33 EDT 2001


> From:	Simon Brunning [SMTP:SBrunning at trisystems.co.uk]
> > 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. 
 
Hmmm. I'll try that again. *Statements* do not return values, expressions
do. An assignment is a statement, so it doesn't return a value. I think that
the rest of this is OK...
 
> 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.
> 
> 
> 
> 
-----------------------------------------------------------------------
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