namespace curiosity

J

J. Michael Caine

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

Little demo illustrates:
.... y[1] = y[1] + 1
.... print y[1]
....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.
 
D

Dennis Lee Bieber

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.

About once a week... It's a FAQ entry!
http://www.python.org/doc/faq/general.html#why-are-default-values-shared-between-objects

Section 7.5 of the Python Reference Manual (at least, in the ActiveState
2.4 release), which should be part of any and all Python installations.

--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
J

J. Michael Caine

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? :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top