namespace curiosity

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J. Michael Caine

    #1

    namespace curiosity

    I just noticed something that may well have an obvious explanation (apologies
    in advance if so).

    Little demo illustrates:
    >>def x(y = {1:1}):
    .... y[1] = y[1] + 1
    .... print y[1]
    ....
    >>x()
    2
    >>x()
    3

    and so on; y continues to be updated rather than reset each call to x().
    dir() suggests that y did _not_ somehow get into the global namespace, nor do
    I see anything else that explains the behavior obviously. This only occurs
    with dicts (or rather, possibly with any object that is merely updated within
    x(), rather than reassigned within x()... I haven't tested).

    I've been pythoning for a little while now, but haven't participated in this
    usenet; you're welcome to consider me a newbie and be gentle with any
    explanation of my oversight or whatever. The nature of this problem made it
    difficult for me to investigate - to see if anyone else has reported or
    explained it.

    TIA.
  • J. Michael Caine

    #2
    Re: namespace curiosity

    On Friday 24 November 2006 17:45, Dennis Lee Bieber wrote:
    About once a week... It's a FAQ entry!
    Wonderful! Missed that. Thanks for humoring me.
    Very satisfying explanation, too... but what else is one to expect from
    Python? :)

    Comment

    Working...