while c = f.read(1)

Grant Edwards grante at visi.com
Fri Aug 19 22:31:57 CEST 2005


On 2005-08-19, sp1d3rx at gmail.com <sp1d3rx at gmail.com> wrote:
> Alright, everyone seems to have gone off on a tangent here, so I'll try
> to stick to your code...

> """
> This is what I would ideally like:
>
>
>   f = open("blah.txt", "r")
>   while c = f.read(1):
>       # ... work on c
>
>
> But I get a syntax error.
>
>
>     while c = f.read(1):
>            ^
> SyntaxError: invalid syntax
>
> """
>
> That's because you are using an assignment operator instead of a
> comparison operator.

That's because he wants an assignment operator.  He also wants
"c = f.read(1)" to be an expression that evalutates to the
value of c after the assignment operator.

-- 
Grant Edwards                   grante             Yow!  .. I'm IMAGINING a
                                  at               sensuous GIRAFFE, CAVORTING
                               visi.com            in the BACK ROOM of a
                                                   KOSHER DELI --



More information about the Python-list mailing list