goto, cls, wait commands

Michael Hoffman cam.ac.uk at mh391.invalid
Thu Feb 10 21:49:14 EST 2005


BOOGIEMAN wrote:
> First of all, what's Python command equivalent to QBasic's "goto" ?

You can only use the goto function if you use Python with line numbers,
thusly:

"""
10 import sys
20 real_stdout = sys.stdout
30 class fake_stdout(object): pass
40 fake_stdout.write = lambda x, y: None
50 sys.stdout = fake_stdout()
60 import this
70 sys.stdout = real_stdout
80 d = {}
90 c = 65
100 i = 0
110 d[chr(i+c)] = chr((i+13) % 26 + c)
120 if i == 26: goto(150)
130 i += 1
140 goto(110)
150 if c == 97: goto(180)
160 c = 97
170 goto(100)
180 print "How zen it is:"
190 print "".join([d.get(c, c) for c in this.s])
"""

z = dict((int(x[0]), " ".join(x[1:])) for x in (y.split() for y in (__doc__ or _).strip().splitlines())); k = [0] + sorted(z.keys()); m = dict((b,a) for a,b in enumerate(k)); l = k[1]

def goto(n): global l; l = k[m[n]-1]

while l and l <= k[-1]: exec z[l]; l = l != k[-1] and k[m[l]+1]

-- 
Michael Hoffman



More information about the Python-list mailing list