2024-09-30 18:32:17 发布
网友
我有一个压缩文件。在那个压缩包里,我有一个plist文件,“还原.plist". 我如何告诉python阅读 当.plist文件到达此部分时停止:
<key>SupportedProductTypes</key> <array> <string>iPhone3,1</string> </array>
我想告诉Python在“SupportedProductTypes”键处停止并将其对应的字符串“iPhone3,1”作为变量记录到内存中,例如“x” 然后打印x。我该怎么做?在
尝试使用xml:
import xml.etree.ElementTree as ET tree = ET.parse("keys.xml") doc = tree.getroot() sup = doc.getiterator("SupportedProductTypes") print doc.getiterator("string")[0].text
给出:
此测试文件名为“密钥.xml“:
<keys> <key>SupportedProductTypes</key> <array> <string>iPhone3,1</string> </array> </keys>
Python标准库中的plistlib处理.plist文件。有关快速教程,请参阅this PyMOTW article。在
plistlib
.plist
另请参见zipfile模块(也在Python标准库中)中的ZipFile类,以从ZIP文件中读取。在
zipfile
ZipFile
尝试使用xml:
给出:
^{pr2}$此测试文件名为“密钥.xml“:
Python标准库中的
plistlib
处理.plist
文件。有关快速教程,请参阅this PyMOTW article。在另请参见
zipfile
模块(也在Python标准库中)中的ZipFile
类,以从ZIP文件中读取。在相关问题 更多 >
编程相关推荐