设置参数进行启动的Python脚本模板

# coding:utf-8
from optparse import OptionParser def migrate_func():
print 'You give the migrate arg\n' def show_func():
print 'You give the show arg-s\n' def grasp_func():
print 'You give the grasp arg-g\n' def parse_func():
print 'You give the parse arg-p\n' def version_func():
print 'You give the versin arg-v\n' if __name__ == '__main__':
_cmd_parser = OptionParser()
_opt = _cmd_parser.add_option
_opt('-g','--grasp',action='store_true',default=False,help='grasp the html file')
_opt('-p','--parse',action='store_true',default=False,help='parse the html have been scrapied')
_opt('-m','--migrate',action='store_true',default=False,help='migrate the result to DB')
_opt('-s','--show',action='store_true',default=False,help='show the introduction of this script')
_opt('-v','--version',action='store_true',default=False,help='sow the version') _cmd_options,_cmd_args= _cmd_parser.parse_args() if _cmd_options.migrate:
migrate_func() if _cmd_options.grasp:
grasp_func() if _cmd_options.parse:
parse_func() if _cmd_options.version:
version_func() if _cmd_options.show:
show_func()
上一篇:Java连接Neo4j的两种方式


下一篇:java文件读写的两种方式