Uplevel functionality
From: Maciej Sobczak (no.spam_at_no.spam.com)
Date: 12/31/03
- Next message: Hans-Joachim Widmaier: "Re: canonical file access pattern?"
- Previous message: Will Stuyvesant: "Re: Project dream"
- Next in thread: Robin Becker: "Re: Uplevel functionality"
- Reply: Robin Becker: "Re: Uplevel functionality"
- Reply: Levente Sandor: "Re: Uplevel functionality"
- Reply: Terry Reedy: "Re: Uplevel functionality"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 31 Dec 2003 10:03:21 +0100
Hello,
I would like to know if there is any possibility in Python to execute
arbitrary scripts in the context higher in the stack frame.
In essence, I would like to have the equivalent of the following Tcl code:
proc repeat {n script} {
for {set i 0} {$i < $n} {incr i} {
uplevel $script
}
}
This allows me to do:
repeat 5 {puts "hello"}
prints:
hello
hello
hello
hello
hello
Or this:
set i 10
repeat 5 {incr i}
puts $i
prints:
15
That second example shows that the script provided as a second parameter
to the "repeat" procedure (the script is "incr i") is executed in the
context where the procedure was called, not locally in the procedure itself.
The strongest analogy to the above repeat procedure in Tcl would be a
hypothetical Python function:
def repeat(n, script):
for i in xrange(n):
EVALUATE script HIGHER IN THE STACK #???
Thank you very much,
-- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/
- Next message: Hans-Joachim Widmaier: "Re: canonical file access pattern?"
- Previous message: Will Stuyvesant: "Re: Project dream"
- Next in thread: Robin Becker: "Re: Uplevel functionality"
- Reply: Robin Becker: "Re: Uplevel functionality"
- Reply: Levente Sandor: "Re: Uplevel functionality"
- Reply: Terry Reedy: "Re: Uplevel functionality"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|