Python中 glob,getpass,OptionParser

http://docs.python.org/library/index.html 在这个连接中有很多关于库的详细描述。

 

简单介绍几个:

 python getpass 保证在console输入的时候不显示密码;


OptionParser 主要是在命令行中构造参数,类似于linux下很多命令可以接受参数的那种;

from optparse import OptionParser

def getScore():
    usage = """use -s to input score"""
    version = "score 1.1"
    parser = OptionParser(usage=usage,version=version)

   
    parser.add_option("-s",dest="score",help ="please input your score")
    #parser.add_option("-v",dest="version",help ="just a test")
    (options, args) = parser.parse_args()
    #print options;
    if (options.score > 90):
        print "you done a great job,you got a A";
    elif (options.score <90 and option.score >80):
        print "You got a B,come on";
    else:
        print "You need work hard"
if __name__ == '__main__':
    getScore();

 

这个包含在lib  optparse中。这个东西不在举例子,你可以看看详细文档上的解释。

 

optparse is a more convenient, flexible, and powerful library for parsing command-line options than the old getopt module. optparse uses a more declarative style of command-line parsing: you create an instance of OptionParser , populate it with options, and parse the command line. optparse allows users to specify options in the conventional GNU/POSIX syntax, and additionally generates usage and help messages for you.

 

glob是一个文件操作相关模块,内容也不多,用它可以查找符合自己目的的文件,就类似于Windows 下的文件搜索,而且也支持通配符,*,?,[]这三个通配符,*代表0个或多个字符,?代表一个字符,[]匹配指定范围内的字符,如[0-9]匹配数字。

 

例如:>>> import glob
>>> glob.glob(r"d:/*.txt")
[]
>>> glob.glob(r"C:/*.txt")
[]
>>> glob.glob(r'C:/*.txt')
[]
>>>
>>> print _
[]
>>> glob.glob(r"D:/work/*.py")
['D://work//test.py', 'D://work//rr.py']

 

smtplib:这个是跟邮件发送相关的lib

 

shutil:

The shutil module offers a number of high-level operations on files and collections of files. In particular, functions are provided which support file copying and removal. For operations on individual files, see also the os module.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

惹不起的程咬金

来都来了,不赏点银子么

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值