首页 > 代码库 > 命令行参数读取和解析
命令行参数读取和解析
1 from argparse import ArgumentParser 2 3 p = ArgumentParser(description=‘eg: $python mm_crawler -n 8 -o "D:/mm_pics" -l 500 4 this command means that your app will create 8 coroutines to download 500 pictures, and save them to D:/mm_pics‘) 5 p.add_argument("-n", type = int, help="Set number of coroutines (default:10)", default=10) 6 p.add_argument("-o", type = str, help=‘Set pictures save path (default:./pics/)‘, default="./pics/") 7 p.add_argument("-l", type = int, help="number of limits of picture to crawl (default:0, no limit)", default=0) 8 9 # p.print_help()10 args = p.parse_args()11 args = vars(args)12 13 #把这些值写到conf.py中14 with open("conf.py",‘wb‘) as conf_file:15 conf_file.write("LIMIT=%s\n" % str(args[‘l‘]))16 conf_file.write("P_THREAD_NUM=%s\n" % str(args[‘n‘]))17 conf_file.write("SAVE_DIR=‘%s‘\n" % args[‘o‘])18 conf_file.close()19 20 # print(args)
命令行参数读取和解析
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。