Class introspection and dynamically determining function arguments

Mark English Mark.English at
Fri Jan 21 12:41:11 EST 2005

Diez B. Roggisch wrote:
> According to this 
> not really - and there are no special moduls neccessary, as 
> everything is at your hands using __dict__ and so on.

Thanks for the link. I'd read that article but found it was too
introductory (what is help, what is sys, etc.). It didn't even deal with
inspect. As such, I didn't think it was definitive about Python's
existing introspection code.

This was much more the level of sophistication I was looking for, albeit
aimed at (static) declared function syntax, rather than (dynamic)
instance or class attributes:

Also, I know the class __dict__ (which is actually a proxy object) may
have class attributes currently, but that seems implementation
dependent. At the moment it lists the attributes defined by *this* type,
regardless of attributes defined in base types. Again, this happens to
be what I want but I don't know that this behaviour is defined anywhere,
and therefore it may be subject to change. It would be nice if I could
ask a class if there are any attributes defined for it in "tp_getset",
although that's just a small step along the path of attribute

(Apologies for interchangeable use of the words type/class)

Nick Coghlan wrote
> Perhaps the simplest way is to require all such classes to have a
> class method that produces a fully populated example instance

Thanks Nick. This was the kind of approach I've ended up going with
(sorta). Still hunting for ideas...

The information contained in this e-mail is confidential and solely 
for the intended addressee(s). Unauthorised reproduction, disclosure, 
modification, and/or distribution of this email may be unlawful. If you 
have received this email in error, please notify the sender immediately 
and delete it from your system. The views expressed in this message 
do not necessarily reflect those of LIFFE Holdings Plc or any of its subsidiary companies.

More information about the Python-list mailing list