摘要: import hashlib # md5加密 obj = hashlib.md5() obj.update('123456'.encode('utf-8')) ret = obj.hexdigest() print(ret) # e10adc3949ba59abbe56e057f20f883e # 加盐版本 obj = hashlib.md5('admin'.encode('utf-8')) ob 阅读全文
posted @ 2019-09-06 15:27 The_small_white 阅读(176) 评论(0) 推荐(0) 编辑
摘要: import configparser # 创建配置文件 config = configparser.ConfigParser() # config={} # config["DEFAULT"] = {'ServerAliveInterval': '45', 'Compression': 'yes', 'Co... 阅读全文
posted @ 2019-09-06 14:27 The_small_white 阅读(218) 评论(0) 推荐(0) 编辑
摘要: import logging # 在文件和窗口二选一个位置打印信息,有filename的话在写入文件 logging.basicConfig( level=logging.DEBUG, # 设置错误级别 filename='logging.txt', # 日志文件名 filemode='w', # 文件打开模式 format='%(asctime)s %(filename)s [%(lineno) 阅读全文
posted @ 2019-09-06 12:43 The_small_white 阅读(139) 评论(0) 推荐(0) 编辑
摘要: import re # findall('正则表达式',‘待匹配的字符串’) #返回匹配到字符串,并存放在列表中 text = 'abcdefg' res = re.findall('a..d', text) print(res) # ['abcd'] # 函数会在字符串内按规则匹配,当找到第一个匹配结果时就结束查找,然后返回一个包含匹配信息的对象,该对象可以 通过 调用group()方法 得到匹 阅读全文
posted @ 2019-09-06 09:56 The_small_white 阅读(161) 评论(0) 推荐(0) 编辑
摘要: import xml.etree.ElementTree as ET # 生成XML new_xml = ET.Element('note') name = ET.SubElement(new_xml, 'to', attrib={'name': 'name'}) name.text = 'George' from_node = ET.SubElement(new_xml, 'from') fro 阅读全文
posted @ 2019-09-05 16:19 The_small_white 阅读(165) 评论(0) 推荐(0) 编辑
摘要: import shelve # 将一个字典写入文件 dic = shelve.open(r'shelve_txt') dic['info'] = {'name': "Kehaimin"} # 使用存入文件的字典 dic = shelve.open(r'shelve_txt') print(dic['info'], type(dic['info'])) # {'name': 'Kehaimin'} 阅读全文
posted @ 2019-09-05 15:16 The_small_white 阅读(138) 评论(0) 推荐(0) 编辑
摘要: import json dic = {'name': 'Kehaimin'} # json.dumps 将数据json序列化(转化为json数据) with open('json.txt', 'w') as f: f.write(json.dumps(dic)) # 等价于 json.dump() ,json,dump专用于文件处理,相当于转化json数据并写入数据 # json.loads 将j 阅读全文
posted @ 2019-09-05 14:56 The_small_white 阅读(245) 评论(0) 推荐(0) 编辑
摘要: import sys # 接受程序运行的参数 ,默认是文件名 res = sys.argv print(res) # (venv3) H:\python\视频练习>python3 sys_model.py # ['sys_model.py'] # 参数中间以空格分隔 # (venv3) H:\python\视频练习>python3 sys_model.py -1111 bbb # ['sy... 阅读全文
posted @ 2019-09-05 14:11 The_small_white 阅读(311) 评论(0) 推荐(0) 编辑
摘要: import os # 获取当前文件目录 current_dir = os.getcwd() print(current_dir) # H:\python\视频练习 # 改变当前脚本工作目录,相当于liunx系统的CD os.chdir('os_dir') current_dir = os.getcwd() print(current_dir) # H:\python\视频练习\os_dir # 阅读全文
posted @ 2019-09-05 11:36 The_small_white 阅读(433) 评论(0) 推荐(0) 编辑
摘要: import random # 0-1的浮点数 float ret = random.random() print(ret) # 0.18216094743707534 # 0-5的整形,包括5 ret = random.randint(0, 5) print(ret) # 2 # 0-5的整形,不包括5 ret = random.randrange(0, 5) print(ret) # 3 # 阅读全文
posted @ 2019-09-03 17:32 The_small_white 阅读(749) 评论(0) 推荐(0) 编辑