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
"Frank Millman" 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 there. It
seems to b
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
> messag
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
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 = {}
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
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 fac
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
Frank Millman wrote:
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
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
Frank Millman wrote:
"MRAB" 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)()
... exc
"MRAB" 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 AttributeError:
> ...
Frank Millman wrote:
On Aug 26, 10:54 am, Chris Rebert wrote:
On Wed, Aug 26, 2009 at 1:22 AM, Frank Millman wrote:
A
class MyClass(object):
def on_message_received(self, msg):
self.method_dict[msg](self)
def method_0(self):
print 'in method_0'
def method_1(self)
On Aug 26, 10:54 am, Chris Rebert wrote:
> On Wed, Aug 26, 2009 at 1:22 AM, Frank Millman wrote:
>
> A
>
> class MyClass(object):
> def on_message_received(self, msg):
> self.method_dict[msg](self)
>
> def method_0(self):
> print 'in method_0'
>
> def method_1(self):
>
On Aug 26, 10:54 am, Chris Rebert wrote:
> On Wed, Aug 26, 2009 at 1:22 AM, Frank Millman wrote:
>
> A
>
> class MyClass(object):
> def on_message_received(self, msg):
> self.method_dict[msg](self)
>
> def method_0(self):
> print 'in method_0'
>
> def method_1(self):
>
On Aug 26, 10:54 am, Chris Rebert wrote:
> On Wed, Aug 26, 2009 at 1:22 AM, Frank Millman wrote:
>
> A
>
> class MyClass(object):
> def on_message_received(self, msg):
> self.method_dict[msg](self)
>
> def method_0(self):
> print 'in method_0'
>
> def method_1(self):
>
On Wed, Aug 26, 2009 at 1:22 AM, Frank Millman 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 = {}
> self.method_dict[0] =
17 matches
Mail list logo