Default method arguments
Bengt Richter
bokr at oz.net
Tue Nov 15 21:59:15 EST 2005
On Tue, 15 Nov 2005 23:51:18 +0100, "Fredrik Lundh" <fredrik at pythonware.com> wrote:
>Steven D'Aprano wrote:
>
>>> Another solution to this is the use of a 'marker' object and identity test:
>>>
>>> _marker = []
>>> class A(object):
>>> def __init__(self, n):
>>> self.data =n
>>> def f(self, x = _marker):
>>> if x is _marker:
>>> x = self.data
>>> print x
>>
>> I would like to see _marker put inside the class' scope. That prevents
>> somebody from the outside scope easily passing _marker as an argument to
>> instance.f.
>
>if you don't want people to be able to easily pass _marker as an argument
>to the f method, you probably shouldn't use it as the default value.
>
LOL ;-)
Regards,
Bengt Richter
More information about the Python-list
mailing list