Accessing variable from a function within a function

Marcin Ciura marcin.ciura at poczta.NOSPAMonet.pl
Sun Jun 24 23:14:00 CEST 2007


Nathan Harmston wrote:
> Unfortunately this doesnt work since a,a1,b,b1 arent declared in the
> function. Is there a way to make these variables accessible to the
> euclid function. Or is there a better way to design this function?

The canonical recommendations are: use attributes of the inner
function or one-element lists as writable variables visible
in the outer function.

Another possibility is to modify the bytecode of the functions
by an appropriate decorator. See
http://www-zo.iinf.polsl.gliwice.pl/~mciura/software/expose.py
(you'll need the byteplay module by Noam Raphael to make it work).
   Marcin



More information about the Python-list mailing list