Python plistlib发布iTunes plist

时间:2016-06-22 15:25:32

标签: python

plistlib读取的Plist文件必须要点,我的问题是iTunes创建了我想要用python读取但仍然没有完成的plists。 例如:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Build Version</key>
    <string>XXXXXX</string>
    <key>Device Name</key>
    <string>Owner's iPad</string>
    <key>Display Name</key>
    <string>Owner's iPad</string>
    <key>GUID</key>
    <string>---</string>
    <key>Last Backup Date</key>
    <date/>                            <---Issue
    <key>Product Type</key>
    <string>iPad2,5</string>
    <key>Product Version</key>
    <string>9.3.1</string>
    <key>Serial Number</key>
    <string>XXXXXXXXX</string>
    <key>Target Type</key>
    <string>Device</string>
    <key>iBooks Data 2</key>
    <data>
    ERORJEIJREWREWRJEWITIJTREKTJKREJTKRETLKRENJLKGTJNREKLGTRELKGRGRG
    RGRDFGFDGRKGIRHJGHRTEGERTJGERFGRGFRGRGRGRTEGRFGFGFGFGFDGFDGFDGFG
    FGFDGFDGFDGIJDHFGUOIHERUOGERHGERHHREIHGIJURHIGJHDFIJGHDIJFHGIFHG
    GFDGOPJDFOPIGJFIDGOIFDJGKJFDGKOFDJGFDJKOGJDFGJDFKGJFDKGJKFFJGJGG
    GFRGREJGOPERJGKJREKGJKLRJGFJGKLFJDLKGJFKLGJKJFGKLJFDGLRNGFIOERHK
    ODFGKODFKGOPFDKJGPDJFPKGJDFPKGJFDKJGKDFJGKJDFKJGKJFKGDFGKFJDGGGJ
    </data>
    <key>iTunes Files</key>
    <dict>
        <key>IC-Info.sidv</key>
        <data>
        FREJEIOTJRIEJTKIREJTJREJGKLRJFRGDLKGDJLKHGHFLKJDHGJLKFHGJKFHJGHFDJG
        FGFDGFDGFDGIJDHFGUOIHERUOGERHGERHHREIHGIJURHIGJHDFIJGHDIJFHGIFHGDGF
        GFGFDPIGJDFIOPGJROKGJKREJGREKLGJNELKRGJDFKJNGLKDFNGKJLNFDLKGNFDLKGN
        GFDGOPJDFOPIGJFIDGOIFDJGKJFDGKOFDJGFDJKOGJDFGJDFKGJFDKGJKFFJGJGGGFF
        GFGFDPIGJDFIOPGJROKGJKREJGREKLGJNELKRGJDFKJNGLKDFNGKJLNFDLKGNFDLKGN
        FGFDGFDGFDGIJDHFGUOIHERUOGERHGERHHREIHGIJURHIGJHDFIJGHDIJFHGIFHGGGG
        FGGFGFDGDFRGFDGFDIOHGIOFDHGDFIOGOIUFDGDFGJHFJUGHFHGJFDHGFHGHFGFHGFJ
        </data>
    </dict>
    <key>iTunes Settings</key>
    <dict>
    </dict>
    <key>iTunes Version</key>
    <string>10.0.1</string>
</dict>
</plist>

我已经在上面指出了plistlib尝试解析这个问题时出现问题我得到了语法错误

如何将我的Python代码 解析为 字符串:

我的Python代码:

import os
import plistlib

def main():

   fileName=os.path.expanduser('example.plist')

   if os.path.exists(fileName):

      pl=plistlib.readPlist(fileName)

      if 'Product Version' in pl:
         print( 'The aString value is %s\n' % pl['Product Version'])

      else:
         print( 'There is no Product Version in the plist\n')

   else:
      print( '%s does not exist, so can\'t be read' % fileName)

if __name__ == '__main__':
   main()

顺便说一句,我的python脚本是打印出版本号

0 个答案:

没有答案