- 论坛徽章:
- 0
|
没用过这个,写了个optparse版的:- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import sys
- import optparse
- def myprint(obj, end='\n'):
- sys.stdout.write(str(obj) + end)
- def getcmdlineargs():
- appargs = {}
- p = optparse.OptionParser()
- p.add_option('-m', action='store', dest='m')
- p.add_option('-N', action='store_true', dest='N')
- p.set_defaults(N=False)
- (opts, args) = p.parse_args()
- appargs['m'] = opts.m
- appargs['N'] = opts.N
- return appargs
- def main():
- args = getcmdlineargs()
- myprint(args)
- if __name__ == '__main__':
- main()
- myprint('done')
复制代码 |
|