Extracting method parameter and default-values?

Emile van Sebille emile at fenx.com
Wed Oct 4 12:23:03 CEST 2000


I think I'd dig into Guido's calltips.py in tools/idle.
That displays the text it sounds like you're looking for and
it should be easy to transform the string into whatever you
want from there.

HTH,

--

Emile van Sebille
emile at fenx.com
-------------------


"Thomas Weholt" <thomas at cintra.no> wrote in message
news:8reo27$lmn$1 at oslo-nntp.eunet.no...
> Hi,
>
> I need to dig my way into an object, find its methods and
extract the
> parameters to that method and their default values.
>
> A test-class:
> >>> class test:
>      def __init__(self):
>           self.a = ''
>      def met(self, b, c = [1,2,3], d = None):
>           self.a = 'thomas'
>           print self.a
> >>>x = test()
>
> I guess its somewhere here :
> >>> x.__class__.__dict__['met'].func_code
>
> where x is my class and met is the name of the method. I
need to get
> something like a dictionary with the parameters and their
default values,
> like:
> params = {'b':'', 'c':[1,2,3],'d':None} ( self is left out
as a parameter
> here )
>
> This would indicate though that b could be left empty, and
that's not right.
> I need a way to detect required parameters too.
> ( I'm making a debug-function that digs its way into an
object and dumps all
> attributes and methods, mostly to learn more about the
Python internals.)
>
> Any ideas?
>
> Thomas Weholt
>
>





More information about the Python-list mailing list