Uplevel functionality

From: Maciej Sobczak (no.spam_at_no.spam.com)
Date: 12/31/03


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/


Relevant Pages

  • Re: Cant put tasks into the calender
    ... you can choose to display the Tasks Pane in the Calendar view ... You can use this script by Paul Berkowitz to do that. ... repeat with theTask in my theTasks ...
    (microsoft.public.mac.office.entourage)
  • Re: Pyramidable
    ... Hi Faucounau alias grapheus. ... You repeat this ... >> State of the art is that it's impossible to decipher an unknown script ... >> signs for such a calendar. ...
    (sci.archaeology)
  • Improving a Contact-from-text script
    ... (I'm placing the script below). ... set firstname to words 1 thru -2 of aLine ... repeat with i from 2 to cnt ... set temp to every word of aLine ...
    (microsoft.public.mac.office.entourage)
  • Re: AppleScript Inquiry
    ... This issue is on an Intel-based Mac running v10.5.2 running Entourage ... We were missing the crucial step of re-saving the script as an ... repeat with aFile in theList ... make new attachment at newMessage with properties {file:aFile as alias} ...
    (microsoft.public.mac.office.entourage)
  • Re: Script menu crashes Entourage 2004 after category deletion
    ... >> set allCategories to categories ... > reason I should be able to get all the categories again from Script Editor ... (That you'd have to do in a repeat loop. ... in Entourage 2004 you ought to be able to delete the whole ...
    (microsoft.public.mac.office.entourage)