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.

你可能感兴趣的:(python,Module,input,import,library,Parsing)