Re: call function of class instance with no assigned name?

2009-05-06 Thread George Oliver
On May 6, 3:07 pm, Carl Banks wrote: > I'm going to guess that you want the keyboardHandler to call method of > commandHandler. There's no reason for commandHandler to be a handler > at all then: keyboardHandler is already handling it. Thanks Carl, you've got it right and your following exampl

Re: call function of class instance with no assigned name?

2009-05-06 Thread Carl Banks
On May 5, 12:17 pm, George Oliver wrote: > A handler would be something like a key input handler. The key input > handler is defined separately from the command handler in the case I > want to use a different method of input, for example a mouse or > joystick. > > In the dictionary of key inputs I

Re: call function of class instance with no assigned name?

2009-05-06 Thread Carl Banks
On May 5, 7:55 pm, Dave Angel wrote: > George Oliver wrote: > > On May 5, 11:59 am, Dave Angel wrote: > > >> 1) forget about getattr() unless you have hundreds of methods in your > >> map.  The real question is why you need two maps. What good is the > >> "command string" doing you?   Why not jus

Re: call function of class instance with no assigned name?

2009-05-05 Thread Dave Angel
George Oliver wrote: On May 5, 11:59 am, Dave Angel wrote: 1) forget about getattr() unless you have hundreds of methods in your map. The real question is why you need two maps. What good is the "command string" doing you? Why not just map the keyvalues directly into function objects?

Re: call function of class instance with no assigned name?

2009-05-05 Thread Rhodri James
On Tue, 05 May 2009 16:52:39 +0100, George Oliver wrote: hi, I'm a Python beginner with a basic question. I'm writing a game where I have keyboard input handling defined in one class, and command execution defined in another class. The keyboard handler class contains a dictionary that maps a

Re: call function of class instance with no assigned name?

2009-05-05 Thread George Oliver
Thanks for the suggestions so far. I've taken the advice to keep things simple so currently I'm just creating one instance of the commandHandler and assigning it a name with command = commandHandler (). This makes it easy to call it from any of the other handlers, and I think this will work for wha

Re: call function of class instance with no assigned name?

2009-05-05 Thread Aaron Brady
On May 5, 2:17 pm, George Oliver wrote: > On May 5, 11:59 am, Dave Angel wrote: > > > 1) forget about getattr() unless you have hundreds of methods in your > > map.  The real question is why you need two maps. What good is the > > "command string" doing you?   Why not just map the keyvalues direc

Re: call function of class instance with no assigned name?

2009-05-05 Thread George Oliver
On May 5, 11:59 am, Dave Angel wrote: > 1) forget about getattr() unless you have hundreds of methods in your > map. The real question is why you need two maps. What good is the > "command string" doing you? Why not just map the keyvalues directly > into function objects? Thanks for the repl

Re: call function of class instance with no assigned name?

2009-05-05 Thread Dave Angel
George Oliver wrote: hi, I'm a Python beginner with a basic question. I'm writing a game where I have keyboard input handling defined in one class, and command execution defined in another class. The keyboard handler class contains a dictionary that maps a key to a command string (like 'h': 'left

Re: call function of class instance with no assigned name?

2009-05-05 Thread George Oliver
On May 5, 9:01 am, Chris Rebert wrote: > On Tue, May 5, 2009 at 8:52 AM, George Oliver > wrote: > > I create instances of these classes in a list attached to a third, > > 'brain' class. > > You could exploit Python's dynamism by using the getattr() function: Thanks for the responses -- I shou

Re: call function of class instance with no assigned name?

2009-05-05 Thread Arnaud Delobelle
Chris Rebert writes: > On Tue, May 5, 2009 at 8:52 AM, George Oliver > wrote: >> hi, I'm a Python beginner with a basic question. I'm writing a game >> where I have keyboard input handling defined in one class, and >> command execution defined in another class. The keyboard handler >> class con

Re: call function of class instance with no assigned name?

2009-05-05 Thread Chris Rebert
On Tue, May 5, 2009 at 8:52 AM, George Oliver wrote: > hi, I'm a Python beginner with a basic question. I'm writing a game > where I have keyboard input handling defined in one class, and command > execution defined in another class. The keyboard handler class > contains a dictionary that maps a k

call function of class instance with no assigned name?

2009-05-05 Thread George Oliver
hi, I'm a Python beginner with a basic question. I'm writing a game where I have keyboard input handling defined in one class, and command execution defined in another class. The keyboard handler class contains a dictionary that maps a key to a command string (like 'h': 'left') and the command hand