Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Error in importing xml.parsers.expat
-
Hi
When I try to import xml.parsers.expat, it gives me the following error. (also when I want to read a plist). Can you show an expample of reading a plist data file?
import xml.parsers.expat
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/var/mobile/Applications/7FEFDAEF-0307-4187-92A2-C5B6C77BF2B5/Pythonista.app/pylib/xml/parsers/expat.py", line 4, in <module>
from pyexpat import *
ImportError: No module named pyexpat -
Sorry about this. I hope that I can fix those problems with the next update.
You can use the somewhat outdated and slow <a href="http://docs.python.org/release/2.4/lib/module-xmllib.html">xmllib</a> for parsing xml (and xml plists).
However, if your goal is to read system plists of iOS, neither that, nor plistlib/expat would help you much – those plists are usually stored in binary format and I don't know of any Python library that can read those.
-
No. I don't want to use binary plists. I Actually I had re-formatted a free English-English dictionary with about 118000 entires to Plist format ('<'key> word '<'key> '<'string>definition'<'string>) and was using it in an app I wrote in Codea. I was going to reconstruct that app in Pythonista too because Pythonista allows me to use my app on my iPod touch too.
So you say for the time being I can not use readPlist function, yes?
If so I will wait for the update.
And after all questions I have to thank you for your great app and patience you have with newbies like me.
-
Thanks michael, but actually I just was using plistlib.readPlist (from your link) when I encountered that error. I guess it is because, from description of plistlib.readPlist in your link, "XML data is parsed using the Expat parser from xml.parsers.expat" when you use plistlib.readPlist.
Thanks anyway.
-
@omz - There is a binary plist library out there - several. Here's one: https://github.com/wooster/biplist Pure python, BSD license.
Unfortunately it doesn't help in this situation because NoneNone is working with an XML plist (plus biplist depends on plistlib for certain things).
Here's a plistlib-free alternative, intended for python 2.4/2.5 - prior to plistlib being available on all OSes:
https://github.com/ishikawa/python-plist-parser
It's MIT licensed. Not sure if it'll solve your problem as it also makes use of the xml module - may end up running into the same parsing issue. Try it and see :)
-
hi
a question: i can easily read mu plist using plistlib of python on my PC. it is a huge plist containing about 118000 entries and their definitions.
i am new to python. is there a solution (a routine) by which i can read the plist on PC and write it as an easily-read-by-python format?
it doesnt't matter if it takes time (30 mins for example) because after that i have a file which can be easily used iny pythonista.
thnx
-
Sure. The root object for most plists is a dict. The json format lends itself well to this. Just load the plist on the PC, which should get you a dict. Then you can do:
Saving a dict/list to a json file:
import json
f = open("dict.json","w")
json.dump(some_dict, f)
f.close()Reading it:
import json
f = open("dict.json")
read_dict = json.load(f)
f.close() -
Yes, JSON is generally a very good format for this kind of thing. If you want the maximum speed, don't care about compatibility with non-Python code and you can trust the data, you can also use the <a href="http://omz-software.com/pythonista/docs/library/marshal.html">marshal</a> module which is very fast for serializing core Python types.
-
thanks pudquick,OMZ
actually i converted my plist to JSON and imported it into my iDevice. it works pretty well.
thanks