Re: Please help with Threading

Discussion in 'Python' started by Chris Angelico, May 20, 2013.

  1. =On Mon, May 20, 2013 at 8:46 PM, Ned Batchelder <> wrote:
    > On 5/20/2013 6:09 AM, Chris Angelico wrote:
    >>
    >> Referencing a function's own name in a default has to have one of
    >> these interpretations:
    >>
    >> 1) It's a self-reference, which can be used to guarantee recursion
    >> even if the name is rebound
    >> 2) It references whatever previously held that name before this def
    >> statement.

    >
    >
    > The meaning must be #2. A def statement is nothing more than a fancy
    > assignment statement.


    Sure, but the language could have been specced up somewhat
    differently, with the same syntax. I was fairly confident that this
    would be universally true (well, can't do it with 'print' per se in
    older Pythons, but for others); my statement about CPython 3.3 was
    just because I hadn't actually hunted down specification proof.

    > So your "apparently recursive" print function is no more
    > ambiguous "x = x + 1". The x on the right hand side is the old value of x,
    > the x on the left hand side will be the new value of x.
    >
    > # Each of these updates a name
    > x = x + 1
    >
    > def print(*args,print=print,lock=Lock(),**kwargs):
    > with lock:
    > print(*args,**kwargs)


    Yeah. The decorator example makes that fairly clear.

    > Of course, if you're going to use that code, a comment might be in order to
    > help the next reader through the trickiness...


    Absolutely!!

    ChrisA
    Chris Angelico, May 20, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KK
    Replies:
    2
    Views:
    496
    Big Brian
    Oct 14, 2003
  2. Replies:
    9
    Views:
    1,000
    Mark Space
    Dec 29, 2007
  3. silkenpy
    Replies:
    1
    Views:
    339
    Dennis Lee Bieber
    Feb 15, 2008
  4. Steven Woody
    Replies:
    0
    Views:
    393
    Steven Woody
    Jan 9, 2009
  5. Steven Woody
    Replies:
    0
    Views:
    428
    Steven Woody
    Jan 9, 2009
Loading...

Share This Page