On Mon, 31 Jan 2005, Jacob S. wrote: ### Pseudocode commandDispatchTable = {'clear' : clearCommand 'quit' : quitCommand 'remove' : removeCommand 'return' : returnCommand 'gatl' : gatlCommand 'ganl' : ganlCommand 'gotl' : gotlCommand 'gonl' : gonlCommand 'getpt' : getplCommand 'regraph': regraphCommand
def evaluate(line): """Evaluates the line.""" pieces = line.split() cmd, rest = pieces[0], pieces[1:] if cmd in commandDispatchTable: dispatchTable[cmd](rest) elif isAssignment(line): ... else: ... ###
The evaluate() function tries to handle the common-case stuff with a dispatch-table method, and otherwise follows up with special-case stuff to handle the rest of the case analysis.
Jacob, if you like this you might want to look into the cmd module, it supports dispatching on the first word of a command with support for help, etc.
step2 = float(y.lstrip("gatl ")) x = float(y.lstrip('gotl ')) x = float(y.lstrip('gonl ')) y = y.lstrip("getpt ")
This code is broken. lstrip('gonl ') will remove *all* leading g, o, n, l and space, in any order: >>> s='go long on log buddy!' >>> s.lstrip('gonl ') 'buddy!'
Instead of y.lstrip('gonl ') you should use y[5:] or maybe y[len('gonl '):]
Kent
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor