5 Answers
+ 6
I just imagine that any thing I could think of is already been implemented in Python :D
+ 5
There is no 'goto' in Python... and anyway, use of 'goto' is considerated as bad practice (even if in low level programming it's an essential function ;P) for high leveled languages.
However, someone had wrote a library as a joke, but you're not supposed to really use it ^^
You can download it here:
http://entrian.com/goto/download.html
And use as:
from goto import goto, label Â
label .start Â
print "It's not good..." Â
for i in range(1, 4):
print i
if i == 2:
try:
output = message # first run time, this will produce error that we catch below
except NameError:
print "Going back to retry with an declared and variable."
message = "Hello"
goto .start Â
print(output)
+ 4
@visph ^.^
Is there a DIM or GOSUB, as well? :D
+ 4
@Kuba:
I don't know ^^
... but you are much experimented than me about Python, and I have no doubt that you could do same kind of google search than me ;P
(the fact is, I'm very new to Python, and this force me to verify some fact before answering, so discovering such freaky things)
+ 3
You might enjoy this thread ("I must use goto"..."you may have the only valid use case..."):
https://stackoverflow.com/questions/6959360/goto-in-JUMP_LINK__&&__python__&&__JUMP_LINK
Because also...
1. The decorator method (far faster)
2. The exception branch method (Python does this to jump out of iterators)
3. The perspective: "....makes state machines faster... ['goto' is like dynamite, for experts a way to remove major obstacles]"
...+ There's always this if you want to go for the jugular :)
from goto import comefrom
comefrom .repeat
s = int(input("Type a number, I'll square it"))
print(s**2)
label .repeat