摘要:
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 阅读全文
摘要:
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'} 阅读全文
摘要:
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 阅读全文
摘要:
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... 阅读全文
摘要:
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 # 阅读全文