Dynamic classes

John Lenton jlenton at gmail.com
Wed Jul 7 11:28:20 EDT 2004


On Wed, 7 Jul 2004 16:19:49 +0100, Steven Johnston
<s.j.johnston at soton.ac.uk> wrote:
> Hi,
> 
> Sorry to mail this list (not sure how big it is) but I have a problem with
> python and was wondering if you may be able to help.
> 
> I have a package that people can add classes to (just copy a class to that
> folder)
> 
> But now I would like to create an instance of the classes based on a set of
> rules (depending on the __init__ signature)
> 
> So my question is: Is there a way of finding out what the signature of a
> class is dynamically without trying to create an instance , and without
> writing a text parser to read the file?

take a look at the documentation for inspect. In particular,
inspect.getargspec(the_class.__init__) might be what you want.

-- 
John Lenton (jlenton at gmail.com) -- Random fortune:
bash: fortune: command not found



More information about the Python-list mailing list