where is upvar

Harald Kirsch kirschh at lionbioscience.com
Wed Sep 20 09:39:11 EDT 2000


Jon Ribbens <jon+python-list at unequivocal.co.uk> writes:

> 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.

Yes, too bad.

> Accessing variables in other peoples' scopes directly is nasty anyway,
> use function arguments ;-).

Not if it is documented and if the sole purpose of a certain function
is to do that in a defined way. Those functions are sometimes called
`control structures'. It seems like Tcl is a bit ahead of Python here,
as it allows to create functions which look, smell and work like
custom made control structures.

  Harald Kirsch

-- 
----------------+------------------------------------------------------
Harald Kirsch   | kirschh at lionbioscience.com | We make the tools to
LION Bioscience | +49 6221 4038 172          | reverse engineer nature.



More information about the Python-list mailing list