Re: Move dictionary from instance to class level

2009-08-30 Thread Frank Millman
Frank Millman fr...@chagford.com wrote: Apologies for the triple-post. I use google-groups for reading c.l.py, but I know that some people reject messages from there due to the volume of spam, so on the odd occasion when I want to send something I fire up Outlook Express and send it from

Re: Move dictionary from instance to class level

2009-08-30 Thread Frank Millman
Anthony Tolle wrote: To take things one step further, I would recommend using decorators to allow symbolic association of functions with the message identifiers, as follows: [...] That's neat. Thanks. Frank -- http://mail.python.org/mailman/listinfo/python-list

Re: Move dictionary from instance to class level

2009-08-28 Thread Frank Millman
Dave Angel wrote: OK, that makes good sense. And I withdraw any suggestion to use pickling, since that could be subject to hacking. It now appears that the messages are only incidentally GUI events. And that you would be well advised to make every possible event a separate message, so

RE: Move dictionary from instance to class level

2009-08-27 Thread Frank Millman
Dave Angel wrote: Any time I see multiple lists like that which have to stay in synch, I think code-smell. I don't think it is that bad, but I agree there is always room for improvement. Why not let the EVT's be passed as strings, and avoid the whole mapping to integers and mapping

RE: Move dictionary from instance to class level

2009-08-27 Thread Frank Millman
Dave Angel wrote: Show me a sample client event handler, and maybe I can suggest how to encode it. For example in wxPython, events are encoded with an event object. You could have the event send the object's type-string as an event ID. No lookup at all. And in fact, one event

Re: Move dictionary from instance to class level

2009-08-27 Thread Dave Angel
Frank Millman wrote: Dave Angel wrote: Show me a sample client event handler, and maybe I can suggest how to encode it. For example in wxPython, events are encoded with an event object. You could have the event send the object's type-string as an event ID. No lookup at all. And in

RE: Move dictionary from instance to class level

2009-08-27 Thread Frank Millman
Dave Angel wrote: Frank Millman wrote: That is definitely *not* what I want to do. I want to make the server as generic as possible, so that it can handle any type of client, hopefully even including a browser eventually. Therefore the server has no knowledge of wxPython event

Re: Move dictionary from instance to class level

2009-08-27 Thread Anthony Tolle
To take things one step further, I would recommend using decorators to allow symbolic association of functions with the message identifiers, as follows: == (MESSAGE_ONE ,MESSAGE_TWO ,MESSAGE_THREE ) = xrange(3) class MyClass(object): method_dict = {}

Re: Move dictionary from instance to class level

2009-08-27 Thread Dave Angel
Frank Millman wrote: Dave Angel wrote: Frank Millman wrote: That is definitely *not* what I want to do. I want to make the server as generic as possible, so that it can handle any type of client, hopefully even including a browser eventually. Therefore the

Move dictionary from instance to class level

2009-08-26 Thread Frank Millman
Hi all I have a class that uses a dictionary to map message numbers to methods. Here is a simple example - class MyClass(object): def __init__(self): self.method_dict = {} self.method_dict[0] = self.method_0 self.method_dict[1] = self.method_1

Re: Move dictionary from instance to class level

2009-08-26 Thread Chris Rebert
On Wed, Aug 26, 2009 at 1:22 AM, Frank Millmanfr...@chagford.com wrote: Hi all I have a class that uses a dictionary to map message numbers to methods. Here is a simple example -    class MyClass(object):        def __init__(self):            self.method_dict = {}            

Re: Move dictionary from instance to class level

2009-08-26 Thread Frank Millman
On Aug 26, 10:54 am, Chris Rebert c...@rebertia.com wrote: On Wed, Aug 26, 2009 at 1:22 AM, Frank Millmanfr...@chagford.com wrote: A class MyClass(object): def on_message_received(self, msg): self.method_dict[msg](self) def method_0(self): print 'in method_0'

Re: Move dictionary from instance to class level

2009-08-26 Thread Frank Millman
On Aug 26, 10:54 am, Chris Rebert c...@rebertia.com wrote: On Wed, Aug 26, 2009 at 1:22 AM, Frank Millmanfr...@chagford.com wrote: A class MyClass(object): def on_message_received(self, msg): self.method_dict[msg](self) def method_0(self): print 'in method_0'

Re: Move dictionary from instance to class level

2009-08-26 Thread Frank Millman
On Aug 26, 10:54 am, Chris Rebert c...@rebertia.com wrote: On Wed, Aug 26, 2009 at 1:22 AM, Frank Millmanfr...@chagford.com wrote: A class MyClass(object): def on_message_received(self, msg): self.method_dict[msg](self) def method_0(self): print 'in method_0'

Re: Move dictionary from instance to class level

2009-08-26 Thread MRAB
Frank Millman wrote: On Aug 26, 10:54 am, Chris Rebert c...@rebertia.com wrote: On Wed, Aug 26, 2009 at 1:22 AM, Frank Millmanfr...@chagford.com wrote: A class MyClass(object): def on_message_received(self, msg): self.method_dict[msg](self) def method_0(self): print

Re: Move dictionary from instance to class level

2009-08-26 Thread Frank Millman
MRAB pyt...@mrabarnett.plus.com wrote in message news:mailman.444.1251290454.2854.python-l...@python.org... An alternative is: class MyClass(object): ... def on_message_received(self, msg): ... try: ... getattr(self, method_%d % msg)() ... except

Re: Move dictionary from instance to class level

2009-08-26 Thread Dave Angel
Frank Millman wrote: MRAB pyt...@mrabarnett.plus.com wrote in message news:mailman.444.1251290454.2854.python-l...@python.org... An alternative is: class MyClass(object): ... def on_message_received(self, msg): ... try: ... getattr(self, method_%d %