default argument depending on another argumen?

Marco Herrn herrn at gmx.net
Thu Nov 7 18:19:17 EST 2002


Gerhard Häring schrieb im Artikel <slrnaslroa.kf.gerhard.haering at lilith.my-fqdn.de>:
> Marco Herrn wrote in comp.lang.python:
>> I want to define a function like this:
>> 
>> def foo(self, bar, x= bar.x):
>>     ....
>>     pass
>> 
>> Now I have the problem that 'bar' isn't really known when defining this
>> function.
>> So how can I achieve this behaviour?
> 
> There's a FAQ entry o this, too IIRC :-)
> 
> The workaround looks like this:
> 
> def foo(self, bar, x=None):
>     if x is None:
>         x = bar.x
>     ...

Thanks again.
I see, I have to look more often on the website ;)

Bye
Marco


-- 
Marco Herrn             herrn at gmx.net
(GnuPG/PGP-signed and crypted mail preferred)
Key ID: 0x94620736




More information about the Python-list mailing list