Hello,
I have the code below:
import argparse
class Myclass(object):
def foo(self):
print 'foo'
def bar(self):
print 'bar'
def test(self,name,place):
print name, place
class Main(Myclass):
def __init__(self):
foo_parser = argparse.ArgumentParser()
foo_parser.add_argument('method')
self.args = foo_parser.parse_args()
def __call__(self, *args, **kws):
method = self.args.method
return getattr(self, method)(*args, **kws)
if __name__ == "__main__":
main = Main()
main()
It's working for functions foo and bar:
5: python arg.py foo
foo
5: python arg.py bar
bar
5: python arg.py test a b
usage: arg.py [-h] method
arg.py: error: unrecognized arguments: a b
But for function test I guess I'm missing something, the idea is to
have N functions and N param.
Any ideas?
Best Regards,
Danilo
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor