469,923 Members | 1,314 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

xml processing

I've like to use python to maintain a small addressbook which lives on a Sharp
Zaurus. This list will never grow beyond 200 or so entries. I've installed
pyxml.

Speaking generally, given a wxpython app to do data entry,
I'm planning to:

1. parse the addressbook file, loading its data into an array.
2. Perform any edit operations within the array.
3. Write out a finished xml file from the array when I'm done.

Is this reasonable? Better, smarter ways to accomplish this?

Thanks for any advice.

Jeff Elkins

Jul 19 '05 #1
4 1299
Jeff Elkins wrote:
I've like to use python to maintain a small addressbook which lives on a Sharp
Zaurus. This list will never grow beyond 200 or so entries. I've installed
pyxml.

Speaking generally, given a wxpython app to do data entry,
I'm planning to:

1. parse the addressbook file, loading its data into an array.
2. Perform any edit operations within the array.
3. Write out a finished xml file from the array when I'm done.

Is this reasonable? Better, smarter ways to accomplish this?


Why XML?

I guess the simplest solution whould be to use pickle.

Saving:
import pickle
l = []
l.append(('Alan', '1st Street', 123456))
l.append(('Ben', '2nd Street', 234567))
l.append(('Clark', '3rd Street', 345678))
f = open('phonebook','w')
pickle.dump(l, f)
f.close()
Loading: import pickle
f2 = open('phonebook')
l = pickle.load(f2)
f2.close()
for item in l: print item
('Alan', '1st Street', 123456)
('Ben', '2nd Street', 234567)
('Clark', '3rd Street', 345678)

The file looks like this: print open('phonebook').read() (lp0
(S'Alan'
p1
S'1st Street'
p2
I123456
tp3
a(S'Ben'
p4
S'2nd Street'
p5
I234567
tp6
a(S'Clark'
p7
S'3rd Street'
p8
I345678
tp9
a.


Ok, the file content might not seem completely obvious, but it's
not really so difficult to parse it, and it's certainly less verbose
than XML. Above all, much less code.

BTW, cPickle is faster than pickle, but I suspect it doesn't matter
with such a small amount of data. It's easy to replace "import pickle"
with "import cPickle as pickle" to try it out.
Jul 19 '05 #2
On Wednesday 01 June 2005 09:51 am, Magnus Lycka wrote:
Jeff Elkins wrote:
I've like to use python to maintain a small addressbook which lives on a
Sharp Zaurus. This list will never grow beyond 200 or so entries. I've
installed pyxml.

Speaking generally, given a wxpython app to do data entry,
I'm planning to:

1. parse the addressbook file, loading its data into an array.
2. Perform any edit operations within the array.
3. Write out a finished xml file from the array when I'm done.

Is this reasonable? Better, smarter ways to accomplish this?


Why XML?

I guess the simplest solution whould be to use pickle.


The Zaurus addressbook app depends on an xml datafile, so I'm stuck with that
format. I just want to to maintenence and data entry on the PC for ease of
use vs typing on the Zaurus' tiny keyboard. I could just edit the raw xml
file, then copy it to the Zaurus, but I'd like to have something a little
spiffier...

Jeff
Jul 19 '05 #3
Jeff Elkins wrote:
I've like to use python to maintain a small addressbook which lives on a Sharp
Zaurus. This list will never grow beyond 200 or so entries. I've installed
pyxml.
If you're not committed to pyxml, you might consider using ElementTree:

http://effbot.org/zone/element-index.htm

I find it *way* easier to work with.

Speaking generally, given a wxpython app to do data entry,
I'm planning to:

1. parse the addressbook file, loading its data into an array.
2. Perform any edit operations within the array.
3. Write out a finished xml file from the array when I'm done.

Is this reasonable? Better, smarter ways to accomplish this?


Seems pretty reasonable. Another option might be to parse the
addressbook file into an XML object and then modify the XML object
itself. E.g.:

tree = ElementTree(file="...")
elem = tree.getroot()
for node in elem.findall("..."):
node.text = "..."

STeVe
Jul 19 '05 #4
On Wednesday 01 June 2005 11:01 am, Steven Bethard wrote:
If you're not committed to pyxml, you might consider using ElementTree:

http://effbot.org/zone/element-index.htm

I find it *way* easier to work with.


Thanks. I've installed it and am experimenting.
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by gl | last post: by
2 posts views Thread by Luiz Vianna | last post: by
4 posts views Thread by Fao, Sean | last post: by
10 posts views Thread by Enrique Cruiz | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.