Plist文件解析错误“'str'对象没有属性'read'”
Plist file parsing error "'str' object has no attribute 'read'"
我正在尝试使用 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
看起来 ptlistlib 需要的是文件而不是字符串:
import plistlib
with open("/Users/Johannes/Pythonproject/test.plist", "rb") as file:
pl = plistlib.load(file)
print pl
我正在尝试使用 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
看起来 ptlistlib 需要的是文件而不是字符串:
import plistlib
with open("/Users/Johannes/Pythonproject/test.plist", "rb") as file:
pl = plistlib.load(file)
print pl