[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: Keyword arguments - strange behaviour?
From:       "Fuzzyman" <fuzzyman () gmail ! com>
Date:       2004-12-28 11:38:09
Message-ID: 1104233889.130130.213780 () z14g2000cwz ! googlegroups ! com
[Download RAW message or body]


Steven Bethard wrote:
> 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

I see. I may be wrong on this... *but* I thought the only time when a
variable defined in the same scope as a function wouldn't be available
in the same namespace is when the function is a global but the variable
isn't ? In which case you deserve a NameError if you try and use the
variable as a default value.......

Are there any other circumstances when they wouldn't be in the same
namespace ?
Regards,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

-- 
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic