In article <bt*************@news.t-online.com>, Peter Otten wrote:
Paradox wrote:
I would like to call a function whose name I supply at runtime.
[snip]
Here's a way to abuse the [] operator (implemented by __getitem__()) to
dynamically select a method...
t["run"]("alpha", "beta", "gamma")
run('alpha', 'beta', 'gamma')
I wouldn't necessarily consider this abuse. This behavior (where
square-bracket- and dot-syntax are functionally equivalent) is the normal
behavior of JavaScript, and it makes dynamic lookup of method names a snap.
Python is more flexible in giving you the option to have separate namespaces
for items and attributes, but if it makes more sense for an object to merge
the two, I see nothing wrong with it.
--
..:[ dave benjamin (ramenboy) -:-
www.ramenfest.com -:-
www.3dex.com ]:.
: d r i n k i n g l i f e o u t o f t h e c o n t a i n e r :