将Python对象序列化为XML(Apple.plist)
我需要从XML中读取和序列化对象,尤其是Apple的.plist格式。在Python中最智能的方法是什么?有现成的解决方案吗?请查看。假设您在Mac上,您可以使用PyObjC 这是一个从plist、from、slide 27读取的示例将Python对象序列化为XML(Apple.plist),python,xml,plist,Python,Xml,Plist,我需要从XML中读取和序列化对象,尤其是Apple的.plist格式。在Python中最智能的方法是什么?有现成的解决方案吗?请查看。假设您在Mac上,您可以使用PyObjC 这是一个从plist、from、slide 27读取的示例 from Cocoa import NSDictionary myfile = "/Library/Preferences/com.apple.SoftwareUpdate.plist" mydict = NSDictionary.dictionaryWithC
from Cocoa import NSDictionary
myfile = "/Library/Preferences/com.apple.SoftwareUpdate.plist"
mydict = NSDictionary.dictionaryWithContentsOfFile_(myfile)
print mydict["LastSuccessfulDate"]
# returns: 2009-08-11 08:38:01 -0600
还有一个给plist写信的例子(我写的):
然后在bash中运行defaults read~/test
时,我得到:
{
Complex = (
47,
"i^2"
);
"Nice Number" = 47;
Truth = 1;
"Universal Sum" = 42;
Vector = (
10,
20,
30
);
}
在Property List Editor.app中打开时,该文件看起来非常漂亮
{
Complex = (
47,
"i^2"
);
"Nice Number" = 47;
Truth = 1;
"Universal Sum" = 42;
Vector = (
10,
20,
30
);
}