where is upvar

Jon Ribbens jon+python-list at unequivocal.co.uk
Wed Sep 20 08:15:08 EDT 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 ;-).

Cheers


Jon

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 mailing list