设置参数进行启动的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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值