#ifdef like question.
Chris Liechti
cliechti at gmx.net
Mon May 13 15:08:12 EDT 2002
"Roman Yakovenko" <romany at actimize.com> wrote in
news:mailman.1021311894.5989.python-list at python.org:
> Hi. I have 2 different implementation of the same class \ function.
> I'd like to use implementation according to some future existence.
> (For example generators).
> How can I choose between 2 implementations in run time( not in install
> time )?
such thing are called factories. e.g. you could define a function which
returns an implementation depending on its args.
def factory(x):
if x:
return Class1()
else:
return Class2()
>>> obj = factory(1)
you can also return the class objects and instantiate later, whatever
chris
PS: you don't need to post in HTML also ASCII is just fine...
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list