asyncore question

S

Stéphane Ninin

Hello,

Probably a stupid question... but still:

why prints None ?



Thanks for your answers,
 
S

snoe

Not 100% sure why print d gives None but if you need to print something
that represents the instance, use repr
<asyncore.dispatcher at 0x8d5be8>


Why isn't __str__ in dir?['__doc__', '__getattr__', '__init__', '__module__', '__repr__',
'_map', 'accept
', 'accepting', 'add_channel', 'addr', 'bind', 'close', 'closing',
'connect', 'c
onnected', 'create_socket', 'debug', 'del_channel', 'handle_accept',
'handle_clo
se', 'handle_connect', 'handle_error', 'handle_expt',
'handle_expt_event', 'hand
le_read', 'handle_read_event', 'handle_write', 'handle_write_event',
'listen', '
log', 'log_info', 'readable', 'recv', 'send', 'set_reuse_addr',
'set_socket', 's
ocket', 'writable']
 
S

Steve Holden

Stéphane Ninin said:
Hello,

Probably a stupid question... but still:




why


prints None ?



Thanks for your answers,
At a guess, because it has a __str__() method that doesn't return
anything, while its __repr__() method is probably inherited from object
or instance.

regards
Steve
 
F

Fredrik Lundh

Stéphane Ninin said:
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>
 
S

Stéphane Ninin

Also sprach Fredrik Lundh :
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".

Thanks: that explains another problem I have
(mixing NNTP and async_chat) at the same time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top