[Tutor] Problem with calling class methods stored in a list
Tobias M.
tm at tobix.eu
Thu Jan 10 14:12:06 CET 2013
Am 10.01.2013 13:48, schrieb Peter Otten:
> If you adopt this approach you might omit the lookup dictionary and use
> getattr():
>
> ... @classmethod
> ... def handle_foo(cls): print "Hello from B.handle_foo()"
> ... @classmethod
> ... def get_handler(cls, packet_type):
> ... return getattr(cls, "handle_" + packet_type)
> ...
Well I think this is an elegant solution.
But due to my protocol a packet type is uniquely defined by a
combination of two header fields (that contain integers). Building a
verbose method name from these would complicate it again.
More information about the Tutor
mailing list