随笔分类 -  常用模块

摘要:作用:用于执行系统命令 常用方法 run 返回一个表示执行结果的对象 call 返回的执行的状态码 obj = subprocess.Popen('tasklistadfasf', # 命令 shell=True, stdout=subprocess.PIPE, #命令正确结果 stderr=sub 阅读全文
posted @ 2018-08-14 21:54 星牧 阅读(104) 评论(0) 推荐(0)
摘要:re 模块 \w 字母数字下划线 \s 所有不可见字符 \d 所有数字 . 所有字符(除了换行符) \b 单词末尾 ^ 行首 $ 行尾 + 1个或多个 * 0个或多个 {m,n} 最少m次,最多n次 {m} 必须是m 次不能多不能少 {,n} 最大n 次 [abc] a|b|c 范围匹配 () 分组 阅读全文
posted @ 2018-08-14 17:09 星牧 阅读(96) 评论(0) 推荐(0)
摘要:configparser 是什么? 配置文件解析模块 什么是配置文件? 用于提供程序运行所需要的一些信息的文件 后缀 ini cfg 有什么用? 方便用户修改 例如超时时间配置文件内容格式 只包括两种元素 section 分区 option 选项 一个文件可以有多个section 一个section 阅读全文
posted @ 2018-08-13 22:21 星牧 阅读(96) 评论(0) 推荐(0)
摘要:hashlib hash是什么? 是一种算法 用于将任意长度的数据,压缩映射到一段固定长度的字符 (提取特征) hash的特点: 1.输入数据不同,得到的hash值有可能相同 2.不能通过hash值来得到输入的值 3.如果算法相同,无论输入的数据长度是多少,得到的hash值长度相同 常用的MD5就是一种has... 阅读全文
posted @ 2018-08-13 22:12 星牧 阅读(111) 评论(0) 推荐(0)
摘要:import xml.etree.ElementTree as ettree = et.parse('a.xml')root = tree.getroot()print(root)#三种查找节点的方式#(1)查找节点的方式 root.iter('year')res = root.iter('year 阅读全文
posted @ 2018-08-13 21:04 星牧 阅读(90) 评论(0) 推荐(0)
摘要:import shelveinfo = {'age':18,'name':'wxx'}info1 = {'age':16,'name':'cxx'}d = shelve.open('db.shv')d['wxx'] = infod["cxx"] = info1d.close()d = shelve.open('db.shv',writeback=True) #改文件d['wxx']['a... 阅读全文
posted @ 2018-08-13 18:07 星牧 阅读(91) 评论(0) 推荐(0)
摘要:import logging# 1. 控制日志级别# 2. 控制日志格式# 3. 控制输出的目标为文件logging.basicConfig(filename='access.log', format='%(asctime)s - %(name)s - %(levelname)s -%(module 阅读全文
posted @ 2018-08-10 18:59 星牧 阅读(177) 评论(0) 推荐(0)
摘要:1 import json 3 dic={'name':'alvin','age':23,'sex':'male'} 4 print(type(dic))# 6 j=json.dumps(dic) 7 print(type(j))# 10 f=open('序列化对象','w') 11 f.write(j) #-------------------等价于jso... 阅读全文
posted @ 2018-08-10 14:19 星牧 阅读(101) 评论(0) 推荐(0)
摘要:1 import random 3 print(random.random())#(0,1) float 大于0且小于1之间的小数 5 print(random.randint(1,3)) #[1,3] 大于等于1且小于等于3之间的整数 7 print(random.randrange(1,3)) 阅读全文
posted @ 2018-08-10 14:07 星牧 阅读(111) 评论(0) 推荐(0)
摘要:3 print(time.time()) # 时间戳:1487130156.419527 4 print(time.strftime("%Y-%m-%d %X")) #格式化的时间字符串:'2017-02-15 11:40:53' # 把一个格式化时间字符串转化为struct_time。实际上它和strftime()是逆操作。 20 print(time.strptime('2011-... 阅读全文
posted @ 2018-08-10 13:30 星牧 阅读(122) 评论(0) 推荐(0)
摘要:os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工作目录;相当于shell下cd os.curdir 返回当前目录: ('.') os.pardir 获取当前目录的父目录字符串名:('..') os.makedirs 阅读全文
posted @ 2018-08-10 13:15 星牧 阅读(108) 评论(0) 推荐(0)