码迷,mamicode.com
首页 > 其他好文 > 详细

命令行参数读取和解析

时间:2014-09-04 18:46:59      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   os   io   ar   div   sp   

 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)

 

命令行参数读取和解析

标签:des   style   blog   color   os   io   ar   div   sp   

原文地址:http://www.cnblogs.com/ajucs/p/3956597.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!