python dynamic scoping question

Grzegorz Adam Hankiewicz gradha at titanium.sabren.com
Mon Apr 21 06:24:13 EDT 2003


On 2003-04-20, Bjorn Pettersen <BPettersen at NAREX.com> wrote:
> > I have a question regarding scoping in python.  I wish to have
> > some mechanism which puts variables at a function level scope
> > into the global scope, dynamically.  I cannot alter my design.
> 
> Good luck, given what you're saying, as opposed to only the
> fragment of code, you would need perfect knowledge of all
> assignments that have dynamically happened in a program, i.e. you
> can't find these variables by static/lexical analysis. I'm almost
> positive there doesn't exists a language where you can perform
> this operation in this direction unless you consider making _all_
> variables global (dynamic scoping does something similar, but in
> the other direction :-)

Hmmm... maybe I don't understand the terminology well, but what
you say seems to be done with TCL's upvar/uplevel keywords, where
you can "overwrite" variables from the global scope, or even a
specific caller level up the stack. I think it's quite funky, and
can keep you from redesigning many things under tight deadlines.
Abusing it of course is bad, as many other things in life.

-- 
 Please don't send me private copies of your public answers. Thanks.





More information about the Python-list mailing list