[Tutor] metaclass question
alan.gauld at btinternet.com
Tue Jan 23 00:15:54 CET 2007
"Kim Branson" <kim.branson at gmail.com> wrote in message
news:DD1B7C36-BF48-4DAF-8DCF-DA30933C095D at gmail.com...
> Hi i'm interested in implementing a factoryclass in python
> What i'd like to do is have my factoryClass produce an instance of a
> class with some methods defined in arguments to the factory class.
> The classes that are produced have many common methods, but a single
> unique method. This method actually is a series of calls to a c++
It sounds like you could create the basic class as normal but
pass in the appropriate function to the init constructor. Then
instead of making it a method create a metjod that calls that
function, something like this:
def __init__(self, myfunc):
self.func = myfunc
Now you can create instances like:
c = C(f1)
d = C(f2)
Is that what you want?
More information about the Tutor