[Tutor] "=" invalid syntax ?
Tim Johnson
tim at johnsons-web.com
Sat Jan 31 12:35:32 EST 2004
* Xuer <linuxasking at netscape.net> [040130 21:19]:
> print all lines of a simple file
>
> test.py
> -----------------------------------------------
> #!/usr/bin/python
>
> try:
> fi = open('test.py', 'r')
> except IOError:
> print 'Can\'t open file for reading.'
> sys.exit(0)
> while (line=fi.readline()):
> print line
> -----------------------------------------------
> then run it
>
> $./test.py
> File "./test.py", line 8
> while (line=fi.readline()):
> ^
> SyntaxError: invalid syntax
>
> what's the problem?
> while (line=fi.readline()):
'=' is an assignment operator in python.
'==' is the comparison operator in python.
use '=='
happens to me all the time ....
tim
--
Tim Johnson <tim at johnsons-web.com>
http://www.alaska-internet-solutions.com
More information about the Tutor
mailing list