Re: Keyword arguments - strange behaviour?

From: Steven Bethard (steven.bethard_at_gmail.com)
Date: 12/23/04


Date: Thu, 23 Dec 2004 16:21:24 GMT

Fuzzyman wrote:
>>>Steven Bethard wrote:
>>>>
>>>>So, one of my really common use cases that takes advantage of the
>>>>fact that default parameters are evaluated at function definition
>>>>time:
>>>>
>>>>def foo(bar, baz, matcher=re.compile(r'...')):
>>>> ...
>>>> text = matcher.sub(r'...', text)
>>>> ...
> Sure.. but you also gave an example of an alternative that was complex,

Interesting. I would have thought that my example was pretty simple.
Maybe it would be helpful to generalize it to:

def foo(bar, baz, spam=badger(x, y, z)):
     ...

All it does is use a default value that was produced by a function call.
  I'm surprised you haven't run into this situation before...

Of course, what is complex or simple is a matter of personal opinion. I
use this pattern so often that it's quite simple to me, but I guess I
can understand that if you don't use such a pattern, it might seem
foreign to you.

Steve



Relevant Pages

  • Re: Keyword arguments - strange behaviour?
    ... Steven Bethard wrote: ... > Fuzzyman wrote: ... > use this pattern so often that it's quite simple to me, ... Hello Steve, ...
    (comp.lang.python)
  • Re: Musical English (chords)
    ... Thanks for your explanation, Steve. ... have been if no chromatism had been allowed! ... pattern, after the first couple we get the pattern, and it becomes ... Too bad from m. 21 the upper part is not stepwise descent because then the ...
    (rec.music.theory)
  • Re: Stupid Question
    ... Steve is right. ... To avoid the hard way, ... >>I want this pattern to appear in my file ...
    (microsoft.public.vc.language)
  • Re: Steve Carroll: What do *you* think the "s" in "Macs" was for?
    ... clearly refers to Steve de Mena and his machine and as Steve ... invested in his erroneous position. ... That's a pattern with Snit... ... begins to lie after he's been shown to be wrong. ...
    (comp.sys.mac.advocacy)
  • Re: Steve Carroll: What do *you* think the "s" in "Macs" was for?
    ... clearly refers to Steve de Mena and his machine and as ... That's a pattern with Snit... ... begins to lie after he's been shown to be wrong. ...
    (comp.sys.mac.advocacy)