爲python腳本增長命令行參數

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

使用標準庫的參數分析模塊, 以屬性的方式, 拿到具體的參數.ui

相關文章
相關標籤/搜索