- 文件查询
from glob import glob
file_paths = "..\\..\\src\\Package\\Repository\\*\\*\\resource.xml"
for file in glob(file_paths):
...
- XML文件读写
import xml.etree.ElementTree as ET
xml_tree = ET.parse(resource_file)
xml_root = xml_tree.getroot()
layers = xml_root.find("SMaterialData/Root/Entity/info/Layers")
materials = layers.findall("Element")
nodeValue = ET.Element('Value')
nodeValue.text = value
materials.append(nodeName)
xml_tree.write(resource_file)
- TXT文件读写
Txt = open("ErrorLog.txt", 'w')
Txt.truncate(0)
Txt.close()
- PKL文件读写
PKL文件可用于存储python对象
import cPickle
logFile = open(filePath, 'wb')
cPickle.dump(obj, logFile)
logFile.close()
logFile = open(filePath, 'r')
data = cPickle.load(logFile)
logFile.close()
- 文件删除
import shutil
delete_fold = shutil.rmtree
delete_fold(file_path)