classobj?

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Tue Feb 27 01:17:04 EST 2007


In <Xns98E3DE8104C0Fvenkynospamcom at 216.77.188.18>, Venky wrote:

>> Do you mean that you want to add it to globals()?
>> 
>> globals()['SomeClass'] = cl
>> 
>> myinst = SomeClass()
>> print isinstance(myinst, SomeClass)
>> print isinstance(myinst, BaseClass)
>> 
> 
> Thanks. That's what I was looking for.

Probably not because now you have to know the name when you write the
static source code.  You said the names are discovered at runtime, so how
do you know it's `SomeClass`?  Put you classes into a dictionary with the
name as key.

`globals()` is a dictionary too, but it is more work to get an object by
name from it (globals()['SomeClass'] vs. some_dict['SomeClass']) and you
don't risk that some of your dynamically created classes overwrites an
existing one with the same name.

Ciao,
	Marc 'BlackJack' Rintsch




More information about the Python-list mailing list