命令行参数读取和解析

 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)

 

转载于:https://www.cnblogs.com/ajucs/p/3956597.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值