[Tutor] newbie-class differs from function?
D2
borelan@wanadoo.fr
Fri Mar 14 11:39:21 2003
Bob Gailer a écrit:
> At 10:06 AM 3/11/2003 -0400, D2 wrote:
>
>> [snip]
>
>
> The "straightforward answer" (written last but appearing first): to get
> the __init__ (or any other) method's parameters:
>
> class c:
> def __init__(self,a,b):pass
> c.__init__.im_func.func_code.co_varnames # returns ('self', 'a', 'b')
>
Notice that if there's another name in the function's body, it will
appear in the tuple returned by co_varnames. So you'll have to use
co_argcount to know the exact number of arguments, and func_defaults to
know the defaults values of arguments and deduct the number of them.
[snip]
> OTOH if you REALLY want to associate the parameter names with the class,
> do this:
>
> class c:
> a=0
> b=0
>
> c.__dict__ # retu5
>
>
> ------------------------------------------------------------------------
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.459 / Virus Database: 258 - Release Date: 2/25/2003