Default method arguments

Steven D'Aprano steve at REMOVETHIScyber.com.au
Wed Nov 16 11:59:07 CET 2005


On Wed, 16 Nov 2005 09:48:47 +0000, Duncan Booth wrote:

> Steven D'Aprano wrote:
>> 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. It also neatly encapsulates everything A needs within
>> A. 
> 
> Surely that makes it easier for someone outside the scope to pass in 
> marker:

>  >>> instance = A(5)
>  >>> instance.f(instance._marker)
>  5

Sure, but they have to explicitly qualify marker with the instance. If
they want to do that, I'm not going to stop them. But I'm trying to avoid
tempting them from doing this:

instance.f(_marker) 

and then complain that it doesn't print _marker.

In other words, I don't want to take away their ability to shoot
themselves in the foot, but I want them to have to *think about it* before
doing so.

 
-- 
Steven.




More information about the Python-list mailing list