Skip to content

Instantly share code, notes, and snippets.

@NathanW2
Created October 4, 2012 14:18
Show Gist options
  • Save NathanW2/3833795 to your computer and use it in GitHub Desktop.
Save NathanW2/3833795 to your computer and use it in GitHub Desktop.
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