Created
October 4, 2012 14:18
-
-
Save NathanW2/3833795 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import inspect | |
def func1(*args): | |
print "IN FUNC1" | |
for arg in args: | |
print arg | |
def func2(arg1, arg2): | |
print "IN FUNC2" | |
print arg1 | |
print arg2 | |
c = { | |
"run" : func1, | |
"refresh": func2 | |
} | |
def runCommandString(cmd): | |
items = cmd.split() | |
cmd = c[items[0]] | |
args = items[1:] | |
print inspect.getargspec(cmd) | |
print "Passing", args , "to", cmd.__name__ | |
try: | |
cmd(*args) | |
except TypeError, err: | |
print err.message | |
if __name__ == "__main__": | |
runCommandString("run arg1 arg2 @arg3") | |
# Not enough args | |
runCommandString("refresh arg1") | |
# Just right | |
runCommandString("refresh arg1 arg2") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment