摘要: import shelve set1 = {'a', 'b', 'c', 'd'} f1 = shelve.open("sh_file.txt") f1['key'] = set1f1.close() f2 = shelve.open("sh_file.txt") print(f2['key'])f 阅读全文
posted @ 2020-05-08 14:53 CherryYang 阅读(74) 评论(0) 推荐(0) 编辑
摘要: import pickle # 还记得bytes类型吗? str1 = "世界" bytes2 = str1.encode('utf-8') print(bytes2) set1 = {'a', 'b', 'c'} print(pickle.dumps(set1)) # 序列化为bytes类型的 i 阅读全文
posted @ 2020-05-08 14:13 CherryYang 阅读(129) 评论(0) 推荐(0) 编辑
摘要: import json #在内存中 数字、字符串、列表、字典、元组 类型数据 序列化后的字符串 dic = dict([('A', '65'), ('B', '66'), ('C', '67')]) dic_str = json.dumps(dic) # dumps() 序列化为字符串 print( 阅读全文
posted @ 2020-05-08 13:45 CherryYang 阅读(122) 评论(0) 推荐(0) 编辑
摘要: import sys print(sys.path) # 以列表按先后顺序列出各python模块的所在路径 import模块时依次查询这些路径 print(sys.platform) # 返回操作系统名称 print(sys.version) # 获取Python解释程序的版本信息 import s 阅读全文
posted @ 2020-05-08 12:33 CherryYang 阅读(111) 评论(0) 推荐(0) 编辑
摘要: import os print(os.getcwd()) # 获取当前工作目录 print(os.listdir()) # 列表列出当前目录下的目录名和文件名 os.mkdir("tempdir") os.chdir("./tempdir") new_dir = os.getcwd() print( 阅读全文
posted @ 2020-05-08 10:52 CherryYang 阅读(144) 评论(0) 推荐(0) 编辑
摘要: import random # 随机整数 r = random.randint(1, 3) # 大于等于1 且小于等于3之间的整数 print(r) r = random.randrange(1, 10, 2) # 大于等于1 且小于10之间的奇数 print(r) # 随机小数 r = rando 阅读全文
posted @ 2020-05-08 09:39 CherryYang 阅读(112) 评论(0) 推荐(0) 编辑