我正在尝试使用plistlib在Mac OSX上读取.plist文件。 可悲的是,我在运行脚本时总是遇到错误
Traceback (most recent call last):
File "/Users/johannes/pycharmprojects/adobe-cache-cleaner/test.py", line 6, in <module>
pl = plistlib.load(fp2)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plistlib.py", line 983, in load
header = fp.read(32)
AttributeError: 'str' object has no attribute 'read'
那是我的剧本:
import plistlib
fp2 = "/Users/Johannes/Pythonproject/test.plist"
pl = plistlib.load(fp2)
print pl
答案 0 :(得分:1)
看起来ptlistlib期待文件不是字符串:
import plistlib
with open("/Users/Johannes/Pythonproject/test.plist", "rb") as file:
pl = plistlib.load(file)
print pl