passing global data to a function

Terry Reedy tjreedy at udel.edu
Mon Dec 1 16:33:35 EST 2003


<beliavsky at aol.com> wrote in message
news:3064b51d.0312010855.66f4e2 at posting.google.com...
> How can I pass global data to function stored in a separate file?

Since 'global data' (and more generally 'context data') is data that
is *not* passed to a function (but is instead read from the function's
context), your question is a contradiction;-).  What you have run into
is the difference between lexical context (where the function is
defined) and dynamic context (where the function is called).  Dynamic
scoping, which you were expecting or at least hoping for has been
tried in some languages (some dialects of Lisp, at least) but I
believe that experience has shown lexical scoping is overall
preferable.

As others have said, your immediate solution is to push the 'global'
value into the functions lexical context with 'funk.ipow = 3'.

Terry J. Reedy






More information about the Python-list mailing list