how to dynamically instantiate an object inheriting from several classes?
steve at REMOVE-THIS-cybersource.com.au
Sat Nov 22 19:09:07 CET 2008
On Sat, 22 Nov 2008 07:32:07 -0700, Joe Strout wrote:
> On Nov 21, 2008, at 7:02 PM, Steven D'Aprano wrote:
>>> I have a function that takes a reference to a class,
>> Hmmm... how do you do that from Python code? The simplest way I can
>> of is to extract the name of the class, and then pass the name as a
>> reference to the class, and hope it hasn't been renamed in the
> Please quit trying to confuse the kids at home. Classes in Python are
> first-class objects, and any time you refer to a class or any other
> object in Python, what you have is a reference to it.
No, at the level of Python code, what you have is the object itself.
What any specific implementation of the Python virtual machine almost
certainly will have are references, or pointers, or some other
implementation-specific form of indirection that eventually leads to the
object. But at the level of Python code, they are invisible. There are no
references at the level of Python code.
The burden of proof lies on you to prove that "reference to a class" has
any meaning at the level of Python code. First you need to define what a
reference is, in terms of *Python* entities (not implementation details),
how it differs from the object itself, and how you can tell "a reference
to a class" apart from the class itself, *at the level of Python code*.
I don't think you can do it, not without conflating implementation-level
details with Python-level details. In Python code, you have objects, and
that is all. Talking about "a reference to a class" instead of "a class"
is simply obscurantism.
More information about the Python-list