A
alf
is there any way to tell the class the base class during runtime?
a.
a.
<class '__main__.B'>is there any way to tell the class the base class during runtime?
[<class '__main__.B'>, <class '__main__.A'>, <type 'object'>]alf said:is there any way to tell the class the base class during runtime?
a.
Example:
Technically, yes - the solution depending on your definition of "duringalf said:is there any way to tell the class the base class during runtime?
bruno said:*But* you'd probably better tell us about the problem you're trying to
solve. Since in Python, inheritance is mostly about implementation (ie:
not needed for subtyping), your problem would probably be best solved
with composition/delegation, for which Python offers a good support:
alf said:I did not think about any particular problem, just thought it would be
cool to abstract out the base class. In fact you can do that in C++ (to
some extend) using templates and parameterizing the base class.
Michele said:alf wrote:
Python is ways cooler than C++.
This is a sensible use case where you may
want to change the base class at runtime:
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.