Instantiating variable classes
Erik Max Francis
max at alcyone.com
Thu Mar 20 04:21:22 EST 2003
Wouter van Marle wrote:
> I am thinking of something like this (don't have a python interpreter
> at
> hand to try):
>
> Instances = [repcls0(), repcls1(), repcls2()]
> myClass = Instances[X]
>
> Should do the job. You basically stuff all your functions in an array
> and
> call the right one directly.
Your code fragment doesn't do that; it calls all the functions and
stores their result in the list. What you probably meant was
functions = [repcls0, repcls1, repcls2]
result = functions[x]()
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ I wake and find that life is / All just duty
\__/ Lamya
EmPy / http://www.alcyone.com/pyos/empy/
A templating system for Python.
More information about the Python-list
mailing list