为python脚本增加命令行参数

时间:2019-02-15 17:48:06   收藏:0   阅读:342
from argparse import ArgumentParser

p = ArgumentParser()
p.add_argument(‘-b‘, ‘--body‘, help=‘Return USN records in comma-separated format‘, action=‘store_true‘)
p.add_argument(‘-c‘, ‘--csv‘, help=‘Return USN records in comma-separated format‘, action=‘store_true‘)
p.add_argument(‘-f‘, ‘--file‘, help=‘Parse the given USN journal file‘, required=True)
p.add_argument(‘-o‘, ‘--outfile‘, help=‘Parse the given USN journal file‘, required=True)
p.add_argument(‘-s‘, ‘--system‘, help=‘System name (use with -t)‘)
p.add_argument(‘-t‘, ‘--tln‘, help=‘TLN ou2tput (use with -s)‘, action=‘store_true‘)
p.add_argument(‘-v‘, ‘--verbose‘, help=‘Return all USN properties for each record (JSON)‘, action=‘store_true‘)
args = p.parse_args()


journalSize = os.path.getsize(args.file)
with open(args.file, ‘rb‘) as i:
    with open(args.outfile, ‘wb‘) as o:
        i.seek(findFirstRecord(i))
        if args.csv:
            do something

使用标准库的参数分析模块, 以属性的方式, 拿到具体的参数.

原文:https://www.cnblogs.com/crb912/p/10384865.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!