asyncore question
Fredrik Lundh
fredrik at pythonware.com
Wed Nov 23 12:45:37 EST 2005
Stéphane Ninin wrote:
> >>> from asyncore import dispatcher
> >>> d=dispatcher()
> >>> print d
> None
> >>> d
> <asyncore.dispatcher at 0x8d9080>
> >>> print type(d)
> <type 'instance'>
> >>> d.__class__
> <class asyncore.dispatcher at 0x008DF150>
> >>> d is None
> False
> >>> ^Z
>
> why
> >>> print d
> prints None ?
it's a tricky one: the dispatcher class has a __repr__ method but no
__str__ method, and it delegates all unknown member accesses to
its socket member:
# cheap inheritance, used to pass all other attribute
# references to the underlying socket object.
def __getattr__(self, attr):
return getattr(self.socket, attr)
and the socket object is None at this point (since the dispatcher hasn't
been initialized). and str(None) is indeed "None".
</F>
More information about the Python-list
mailing list