Python 扩展 OSX 路径,其中包含空格
我正在尝试修改 plist 文件: /Volumes/MacintoshHD/Users/christian/Library/Application Support/iPhone Simulator/4.3.2/Library/Preferences/com.apple.Accessibility.plist
这是我的 noob python 脚本:
import plistlib
import os.path
#set path
prefs_path = os.path.expanduser("~/Library/Application\ Support/iPhone\ Simulator/5.0/Library/Preferences/com.apple.Accessibility.plist")
#parse
prefs = plistlib.readPlist(prefs_path)
我得到 IOError: 2, 'No such file or directory'
如果我从我得到的路径中删除反斜杠ExpatError:'格式不正确(无效令牌):第 1 行,第 8 列'
更新
Ignacio Vazquez-Abram 的回答表明该文件已损坏。它仍然可以使用 Xcode 进行编辑并使用 Quicklook 进行查看。模拟器也运行良好。
当我在textmate中打开它时,我看到的只是:
bplist00ÿ
D _ApplicationAccessibilityEnabled_VOTQuickNavEnabled_AccessibilityEnabled]ScreenCurtain_"VoiceOverTouchRotorItemsPreference_AXInspector.enabled_AXInspector.frame_AXInspectorEnabled Ø"%(+.147:=@“ YRotorItemWEnabledYCharacter “ TWord “ TLine “ VHeader “ TLink “ [FormElement “# ZTableStart “&YListStart“)YLandmarks“,[VisitedLink“/^NonVisitedLink“2VButton“5YTextField“8UImage“;ZStaticText“>\InternalLink“ATZoom_{{0, 0}, {276, 166}} ;Pguö∞ƒŸ⁄€‹›Òˆ#().56;@AFRSXcdistyÉÑâïñõ™´∞∑∏Ω«»Õ”‘Ÿ‰Â͘¯˝F
iPhone模拟器plists无法通过python编辑还是这是一个损坏的文件?有办法解决这个问题吗?
I'm trying to modify the plist file at: /Volumes/MacintoshHD/Users/christian/Library/Application Support/iPhone Simulator/4.3.2/Library/Preferences/com.apple.Accessibility.plist
Here's my noob python script:
import plistlib
import os.path
#set path
prefs_path = os.path.expanduser("~/Library/Application\ Support/iPhone\ Simulator/5.0/Library/Preferences/com.apple.Accessibility.plist")
#parse
prefs = plistlib.readPlist(prefs_path)
I get IOError: 2, 'No such file or directory'
If I remove the backslashes from the path I get ExpatError: 'not well-formed (invalid token): line 1, column 8'
Update
Ignacio Vazquez-Abram's answer suggests that the file is corrupted. It's still editable with Xcode and viewable with Quicklook. Also the simulator works fine.
When I open it in textmate all I see is this:
bplist00ÿ
D _ApplicationAccessibilityEnabled_VOTQuickNavEnabled_AccessibilityEnabled]ScreenCurtain_"VoiceOverTouchRotorItemsPreference_AXInspector.enabled_AXInspector.frame_AXInspectorEnabled Ø"%(+.147:=@“ YRotorItemWEnabledYCharacter “ TWord “ TLine “ VHeader “ TLink “ [FormElement “# ZTableStart “&YListStart“)YLandmarks“,[VisitedLink“/^NonVisitedLink“2VButton“5YTextField“8UImage“;ZStaticText“>\InternalLink“ATZoom_{{0, 0}, {276, 166}} ;Pguö∞ƒŸ⁄€‹›Òˆ#().56;@AFRSXcdistyÉÑâïñõ™´∞∑∏Ω«»Õ”‘Ÿ‰Â͘¯˝F
Are the iPhone simulator plists not editable by python or is this a corrupted file? Is there a way around this?
expat 错误意味着您已找到该文件,但其中有问题。打开文件并验证它没有被损坏。
编辑:
啊啊,这是一个二进制plist。是的,plistlib 无法处理这些。您需要
libplist
代替。The expat error means that you've gotten to the file, but there's something wrong with it. Open the file and verify that it's not been corrupted.
EDIT:
Aaah, it's a binary plist. Yeah,
plistlib
can't handle those. You wantlibplist
instead.