By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,272 Members | 1,733 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,272 IT Pros & Developers. It's quick & easy.

namespace curiosity

P: n/a
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.
Nov 25 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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? :)
Nov 25 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.