homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author djc
Recipients djc
Date 2010年04月21日.10:55:22
SpamBayes Score 2.5159451e-08
Marked as misclassified No
Message-id <1271847325.07.0.737920517858.issue8483@psf.upfronthosting.co.za>
In-reply-to
Content
This is rather confusing:
Python 2.6.4 (r264:75706, Mar 8 2010, 08:41:55)
[GCC 4.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket, asyncore
>>> class T:
... pass
...
>>> t = T()
>>> print t
<__main__.T instance at 0x18237a0>
>>> print repr(t)
<__main__.T instance at 0x18237a0>
>>> class A(asyncore.dispatcher):
... pass
...
>>> a = A()
>>> print a
None
>>> print repr(a)
<__main__.A at 0x179c0e0>
>>> class B(asyncore.dispatcher):
... def __init__(self, *args):
... asyncore.dispatcher.__init__(self, *args)
...
>>> sock = socket.socket()
>>> b = B(sock)
>>> print b
<socket._socketobject object at 0x7fcef226e8a0>
>>> print repr(b)
<__main__.B at 0x179c0e0>
Here's dispatcher's __repr__:
 def __repr__(self):
 status = [self.__class__.__module__+"."+self.__class__.__name__]
 if self.accepting and self.addr:
 status.append('listening')
 elif self.connected:
 status.append('connected')
 if self.addr is not None:
 try:
 status.append('%s:%d' % self.addr)
 except TypeError:
 status.append(repr(self.addr))
 return '<%s at %#x>' % (' '.join(status), id(self))
Which doesn't seem excessively complex...
History
Date User Action Args
2010年04月21日 10:55:25djcsetrecipients: + djc
2010年04月21日 10:55:25djcsetmessageid: <1271847325.07.0.737920517858.issue8483@psf.upfronthosting.co.za>
2010年04月21日 10:55:24djclinkissue8483 messages
2010年04月21日 10:55:22djccreate

AltStyle によって変換されたページ (->オリジナル) /