Peter Otten wrote:
Build the list outside the class: MyClass.method_list = [MyClass.bar]
Thanks, that is a solution. But I don't really like to put the list outside the class as it is strongly related to the class and not used outside.

Hugo Arts wrote:
What piece of your code requires this list? Perhaps we can redesign that to be rid of it.
Actually in my code it's not a list but a dictionary. The class is part of a network server and handles incomming packets. It reads the header of the packet and determines the packet type. The dictionary has the packet type as key and the method to handle the packet of the corresponding type as value. So the dictionary is used to look up the correct method to process the packet.

With this I try to avoid a lot of "if...elif..." statements and make it easy to expand the network protocol by just adding a new handle method and put it in the dictionary.
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to