摘要: 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) 编辑