[Tutor] Why is it...

Kent Johnson kent37 at tds.net
Thu Mar 22 19:54:34 CET 2007


Jay Mutter III wrote:
> Why is it that when I run the following interactively
> 
> f = open('Patents-1920.txt')
> line = f.readline()
> while line:
>      print line,
>      line = f.readline()
> f.close()
> 
> I get an error message
> 
> File "<stdin>", line 4
>      f.close()
>      ^
> SyntaxError: invalid syntax
> 
> but if i run it in a script there is no error?

Can you copy/paste the actual console transcript?

BTW a better way to write this is
f = open(...)
for line in f:
     print line,
f.close()

Kent

> 
> Thanks
> 
> Jay
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 



More information about the Tutor mailing list