I have a file that has the following contents:
a
b
c
d
I'm reading this in Python using the following code:
f = open('foo.txt')
w = f.readline()
while w is not '' :
print w
w = f.readline()
According to the docs
if f.readline() returns an empty string, the end of the file has been reached
Why then do I go into an infinite loop?
w != ''makes it work fine. I'd still like to know whyis notcauses an infinite loop.while w is not '' :, just writewhile w: