Strange loop behavior
Peter Otten
__peter__ at web.de
Wed Mar 26 04:41:24 EDT 2008
Gabriel Rossetti wrote:
> I wrote a program that reads data from a file and puts it in a string,
> the problem is that it loops infinitely and that's not wanted, here is
> the code :
>
> d = repr(f.read(DEFAULT_BUFFER_SIZE))
> while d != "":
> file_str.write(d)
> d = repr(f.read(DEFAULT_BUFFER_SIZE))
> And yes I checked, the "d" variable is en empty string at some point, so
> the looping should stop.
d may be an empty string, but repr(d) isn't:
>>> d = ""
>>> print repr(d)
''
>>> print d
Remove the two repr() calls and you should be OK.
Peter
More information about the Python-list
mailing list