uplevel

How to localize a variable in an upper scope in Perl?

I have run across the following pattern a few times while developing Perl modules that use AUTOLOAD or other subroutine dispatch techniques: sub AUTOLOAD { my $self = $_[0]; my $code = $self->figure_out_code_ref( $AUTOLOAD ); goto &$code; } This works fine, and caller sees the correct scope. Now what I would like to do ...

does python 2.5 have an equivalent to Tcl's uplevel command?

Does python have an equivalent to Tcl's uplevel command? For those who don't know, the "uplevel" command lets you run code in the context of the caller. Here's how it might look in python: def foo(): answer = 0 print "answer is", answer # should print 0 bar() print "answer is", answer # should print 42 def bar(): u...