472,340 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,340 software developers and data experts.

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 1336
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Newbie | last post by:
I am doing some robotics projects but my main area of interest is trying out several algorithms for the processing of the stream of data coming...
4
by: gl | last post by:
I have just started a project that's going to do very heavy credit card processing through asp.net and i had some questions. I've never really done...
0
by: Ganapathy | last post by:
I have COM dll code written in VC 6.0. When i tried compiling this code in VC 7, The MIDL cmpiler gets called twice. i.e. it initially compiles...
2
by: Luiz Vianna | last post by:
Hi folks, I got a problem that certainly someone had too. After a user request, I (my server) must process a lot of data that will expend some...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and...
2
by: domtam | last post by:
Hi all, Here is what I want: when a user clicks a <asp:button>, its event handler will do some server-side processing and then pop up a windows...
4
by: Fao, Sean | last post by:
I'm trying to show an animated image temporarily while the web server is processing a long request. I attempted to use a combination of CSS styles...
10
by: Enrique Cruiz | last post by:
Hello all, I am currently implementing a fairly simple algorithm. It scans a grayscale image, and computes a pixel's new value as a function of...
0
ADezii
by: ADezii | last post by:
In the Tip of the Week #19, we demonstrated Transaction Processing, specifically as it applies to DAO (Data Access Objects). In this week's Tip,...
0
by: tavares | last post by:
(Our apologies for cross-posting. We appreciate if you kindly distribute this information by your co- workers and colleagues.) ...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.