call function of class instance with no assigned name?
georgeoliverGO at gmail.com
Tue May 5 13:28:43 EDT 2009
On May 5, 9:01 am, Chris Rebert <c... at rebertia.com> wrote:
> On Tue, May 5, 2009 at 8:52 AM, George Oliver <georgeolive... at gmail.com> 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 should have mentioned that I looked at
the getattr() function, but as I instantiate the key handler and
command handler classes in a list (like handlers = [command_handler(),
keyboard_handler()], I'm unsure how to reference that class instance
in the getattr in a straightforward way (short of keeping track of
each instance's position in the handlers list). Is there a typical way
of doing that?
More information about the Python-list