Default method arguments
Fredrik Lundh
fredrik at pythonware.com
Tue Nov 15 17:51:18 EST 2005
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.
</F>
More information about the Python-list
mailing list