1.config 模块
1 import configparser 2 3 conf = configparser.ConfigParser() 4 conf["DEFAULT"] = {‘ServerAliveInterval‘: ‘45‘, 5 ‘Compression‘: ‘yes‘, 6 ‘CompressionLevel‘: ‘9‘} 7 conf[‘wwwwwwwww‘] = {} 8 conf[‘wwwwwwwww‘][‘user‘] = ‘baidu‘ 9 conf[‘topsecret.server.com‘] = {} 10 topsecret = conf[‘topsecret.server.com‘] 11 topsecret[‘Host Port‘] = ‘50022‘ 12 with open(‘conf.ini‘,‘w‘) as f: 13 f.write(conf)
2.hashlib操作
1 import hmac 2 h = hmac.new(b‘hsc‘) 3 h.update(b‘12233‘) 4 print(h)
3.random模块
1 import random 2 print(random.random()) 3 print(random.randint(1,2)) #0,1,2 随机 4 print(random.randrange(1,2))#0,1 随机 5 6 checkcode = ‘‘ 7 for i in range(6): 8 current = random.randrange(0,6) 9 if current != i: 10 temp = chr(random.randint(65,90)) 11 else: 12 temp = random.randint(0,9) 13 checkcode += str(temp) 14 print(checkcode)
4.shelve模块
1 import shelve 2 3 d = shelve.open(‘shelve_test‘) 4 5 def stu_data(name,age): 6 print("register stu",name,age) 7 name = ["hsc","xjp","abm"] 8 info = {"name":"hsc","age":18} 9 10 d["test"] = name 11 d["info"] = info 12 d[‘func‘] = stu_data
5.shutil模块
1 import shutil 2 3 # f1 = open("random mod .py") 4 # f2 = open("random_new .py",‘w‘) 5 # shutil.copyfileobj(f1,f2) 6 7 # shutil.copyfile("笔记",r‘d:\123‘) 8 shutil.make_archive(‘www‘,‘gztar‘,root_dir=r‘C:\Users\heshaochuan\PycharmProjects\py_s15\day6‘)
6. logging模块
1 import logging 2 3 log_test = logging.getLogger(‘TEST‘) 4 logging.basicConfig(filename=‘wwwwwwwwww.log‘,level=logging.INFO) 5 logging.debug(‘mthgh‘) 6 logging.info(‘2131234324‘)
7.re模块
常用正则表达式符号
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|