Class introspection and dynamically determining function arguments

Diez B. Roggisch deetsNOSPAM at web.de
Thu Jan 20 07:12:39 EST 2005


Mark English wrote:

> The only way I can imagine to do this is to create an instance of the
> class in question, and then start poking around in its attributes
> dictionary (initially just using dir). So firstly, if there is instead a
> way to do this without creating an instance I'd be interested.

This is the only way to go, as python has no attribute declarations as
static compiled languages have. But of course not all classes may feature
default constructors so that creating an instance is impossible. Or you
create unwanted sideeffects - think of the notorious class
DeleteMyHarddisk....

As youself already mentioned that maybe you have to impose certain
prerequisites, you maybe want to extend this to the point where for each
class you want to make dynamically instantiatable you need some
declaration. This of course depends on your desired application - whatfor
is it planned? 

-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list