where is upvar
jon+python-list at unequivocal.co.uk
Wed Sep 20 14:15:08 CEST 2000
Harald Kirsch <kirschh at lionbioscience.com> wrote:
> def bla(someparams, upvars=local())
> upvars['parentsVar'] = "some value set in parent stack frame"
I think that will give you the local variables in the scope that
the function was defined in, not the scope it is called from.
If you want to access a variable in the global scope, use the 'global'
keyword. Python only looks in the local scope and the global scope, it
does not look at things in-between like some other languages do.
Accessing variables in other peoples' scopes directly is nasty anyway,
use function arguments ;-).
PS. I only started looking at Python this week, and I've never written
a program in it. I may quite possibly be completely wrong ;-)
More information about the Python-list