while c = f.read(1)

Steven Bethard steven.bethard at gmail.com
Fri Aug 19 17:52:56 CEST 2005


Antoon Pardon wrote:
> But '', {}, [] and () are not nothing. They are empty containers.
> And 0 is not nothing either it is a number. Suppose I have
> a variable that is either None if I'm not registered and a
> registration number if I am. In this case 0 should be treated
> as any other number.

This is why None is a singleton::

     if registration_number is None:
         # do one thing
     else:
         # do another

In the OP's case, if file.read() had happened to return None instead of 
the empty string, he probably would've wanted to do the same thing. 
OTOH, people on python-dev have said that the file.read() idiom of 
returning '' when it's done should be replaced by a true iterator, i.e. 
using StopIteration.  (I don't know the details of exactly how things 
would change, but I suspect this is something that will happen in Python 
3.0.)

STeVe



More information about the Python-list mailing list