我有100+保存的omnigraffle文件,需要写一个脚本来读取,然后修改它的内容。
例一:
https://www.dropbox.com/s/97cec5err3qubgq/test.graffle?dl=0
我可以通过TextMate打开它,文件的内容是xml格式的
<?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>ActiveLayerIndex</key>
<integer>0</integer>
<key>ApplicationVersion</key>
<array>
<string>com.omnigroup.OmniGraffle6</string>
<string>163.7.0.243167</string>
</array>
<key>AutoAdjust</key>
<true/>
<key>BackgroundGraphic</key>
<dict>...因此,我编写了用Python读写该文件的代码。
contents = open(filename).read()
print contents结果是
?]Ys?8~N~?֯IxgO?Gbg}?%?;)Wm?$sB
4???=?z?;F.??l??h?O????q??ش7~?z???ݓ???{??s#?8=?><?il4??Nx?????6N??o???;?hl?0?o????[XP???VF?Ӑ$d????&?????&i=????????o6??ǭN??w???????Ͷ?+/t}FF$?????
?yװ5???aWT??pT?ۥ??v??r???O??Û?u٣GR?)?I!o?~MK??|7??)[)c?'2;|@g#1?J/?!??Jo?X;ؿ??I??t%L?2Jy&?]?;)ЧC^?D????ܑ_`
????{?l?????h????]?7.?y?]7 ?&?那么,如何在Python/PHP中读取该文件呢?
发布于 2016-03-13 00:28:40
您提供的链接中的文件是用gzip压缩的,或者是存储的,或者是下载时由dropbox压缩的,以节省空间。
要么在文件上运行gunzip命令,然后再使用它,要么使用python gzip模块:
import gzip
with gzip.open(filename) as f:
contents = f.read()https://stackoverflow.com/questions/35965036
复制相似问题