I'm coming from Tcl-world ...
geek
geek+ at andrew.cmu.edu
Fri Aug 2 10:33:13 EDT 2002
> 2.) A 'switch'-thing: like a big if-elif-elif-elif-...-else but
> which evaluates its expression only once ... and then does all the
> comparisons.
I'm one of those weirdos that would use a dictionary for this. Here's
a very poor example:
#!/usr/bin/env python
import sys
def yes():
print 'yes'
return
def no():
print 'no'
return
options = {'-y': yes,
'-n': no,
}
for o in sys.argv[1:]:
try:
options[o]()
except:
print 'Unknown command line arguement'
More information about the Python-list
mailing list