Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Python对象序列化为XML(Apple.plist)_Python_Xml_Plist - Fatal编程技术网

将Python对象序列化为XML(Apple.plist)

将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

我需要从XML中读取和序列化对象,尤其是Apple的.plist格式。在Python中最智能的方法是什么?有现成的解决方案吗?

请查看。

假设您在Mac上,您可以使用PyObjC

这是一个从plist、from、slide 27读取的示例

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
    );
}