Keyword arguments - strange behaviour?

Steven Bethard steven.bethard at gmail.com
Sat Dec 25 12:30:46 EST 2004


Fuzzyman wrote:
> It wasn't that part of the example that I thought was over complex.
> (although it's not a 'pattern' I use often). You suggested that if we
> had dynamic evaluation of default values, you would have to replace it
> with :
> 
>>>>>class foo(object):
>>>>>    matcher=re.compile(r'...')
>>>>>    def __new__(self, bar, baz, matcher=None):
>>>>>        if matcher is None:
>>>>>            matcher = self.matcher
>>>>>        ...
>>>>>        text = matcher.sub(r'...', text)
>>>>>        ...
> 
> 
> Now that I thought was over complex... when all you wanted to do was
> put a constant into your default value !

Ahh.  Yeah, the thing above is a bit complex, but it keeps the same 
namespaces -- matcher is only available to foo, not the enclosing 
class/module.  Point taken of course. ;)

Steve



More information about the Python-list mailing list