Default method arguments
Steven D'Aprano
steve at REMOVETHIScyber.com.au
Wed Nov 16 05:46:34 EST 2005
On Wed, 16 Nov 2005 02:59:15 +0000, Bengt Richter wrote:
> On Tue, 15 Nov 2005 23:51:18 +0100, "Fredrik Lundh" <fredrik at pythonware.com> 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.
>>
>>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 ;-)
Ha ha *wink*
What I meant was to discourage people from treating _marker as just
another ordinary sort of object, then making pointless bugs
reports "when you pass _marker as the argument to the f method, it doesn't
print _marker but instead prints something else."
My philosophy is, any time you have an object that has a magic meaning
(e.g. as a sentinel), don't tempt your users to try to use it as if it
were an ordinary object.
--
Steven.
More information about the Python-list
mailing list