share function argument between subsequent calls but not between class instances!

Ben Finney bignose+hates-spam at benfinney.id.au
Sat Feb 18 17:13:11 EST 2006


Duncan Booth <duncan.booth at invalid.invalid> writes:
> If you intend to only use the default some of the time, and at other
> times pass in a different list, then save the 'default' in the
> instance and use a special marker value to indicate when you intend
> the default to be used:

The most common idiom for such a marker is the None value.

    class Test(object):
        def __init__(self):
            self.L = []
        def f(self, a, L=None):
            if L is None:
                L = self.L
            L.append(a)
            return L

-- 
 \        "Consider the daffodil. And while you're doing that, I'll be |
  `\           over here, looking through your stuff."  -- Jack Handey |
_o__)                                                                  |
Ben Finney <http://www.benfinney.id.au/>



More information about the Python-list mailing list