Dave Angel wrote:
But as it's the simplest solution, and one with no runtime overhead, you
really should consider it.  Having a line or two following the class
definition is not uncommon in Python, and comments can make sure the
reader of the code understands it's part of the class initialization.

If that really offends you, put the code in a _setup() method of the
same class, and run MyClass._setup() immediately after defining the
class.  _setup() can be a classmethod as well, and you could have it
protect itself against running more than once, perhaps by refusing to
run if the list/dict already contains entries.

Interesting objection! However I'll probably implement the solution using __get__(None, cls) to get the method from the dictionary. It doesn't really add complexity and the additional overhead is insignificant in my use case. There will be only one client connected at a time and not much communication. The time the server will need to process the packet data will be disproportionally larger than the time to read the header and choose the handler method.

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to