selecting base class from user input
Jackson
jackson at hotmail.com
Sun Aug 13 16:27:14 EDT 2006
I want a class that will determine its base class by the argument passed
in. What I am about to write _does_not_work_, but it shows what I am
trying to do.
class ABC(some_super):
def __init__(self,some_super):
some_super.__init__(self)
if some_super == list:
self.append('ABC')
elif some_super == dict:
self['ABC'] = None
Then, the user can call this function:
>>> example = ABC(list)
>>> print example
['ABC']
>>> example = ABC(dict)
>>> print example
{'ABC': None}
Clearly, this is a bad example, but the central idea is what I am trying
to do. ABC is a particular example which can be represented in various
forms. I want an ABC class that will create the example in the form
specified by the user.
So how can I achieve this? Thanks.
More information about the Python-list
mailing list