ANNOUNCE: 'goto' for Python
Richie Hindle
richie@entrian.com
Thu, 01 Apr 2004 08:10:57 +0100
Entrian Solutions is pleased to announce version 1.0 of the 'goto' module.
This adds the 'goto' and 'comefrom' keywords to Python 2.3, adding
flexibility to Python's control flow mechanisms and allowing Python
programmers to use many common control flow idioms that were previously
denied to them.
'goto' example: breaking out from a deeply nested loop:
from goto import goto, label
for i in range(1, 10):
for j in range(1, 20):
for k in range(1, 30):
print i, j, k
if k == 3:
goto .end
label .end
print "Finished\n"
'comefrom' example: letting cleanup code take control after an error.
from goto import comefrom, label
def bigFunction():
setUp()
if not doFirstTask():
label .failed
if not doSecondTask():
label .failed
if not doThirdTask():
label .failed
comefrom .failed
cleanUp()
Computed 'goto's are also supported - see the documentation for details.
Computed 'comefrom's are planned for a future release.
Documentation and further examples:
http://entrian.com/goto/index.html
Downloads:
http://entrian.com/goto/download.html
The 'goto' module is released under the Python Software Foundation
license, and requires Python 2.3 or later.
Please note that this version does not work at the interactive Python
prompt - code importing 'goto' must be in a .py file. This restriction
will hopefully be lifted in a future release.
--
Richie Hindle
richie@entrian.com