xml with python <-> python deprecated - why?

Frank Millman frank at chagford.com
Tue Dec 20 07:06:10 EST 2005


Hi all

I need to pass data between a server program and a client program, both
written in Python.

My first thought was to use xml. The server builds up an xml string,
without using any xml tools. The client uses Sax to parse the string
received. Here is an example.

The server passes to the client the widgets required to set up a
screen. This is how it tells it to display a button -

    self.gui += '<button label="%s" ref="%s" enabled="%s"
default="%s"/>' \
        % (label,ref,enabled,default)

This is how the client deals with this -

    MyButton(self.panel,attrs['label'],int(attrs['ref']),
        int(attrs['enabled']),int(attrs['default']))

I have recently read that it is not a good idea to use xml unless it is
a specific requirement, so I changed it to passing a list of
dictionaries.

The server code now looks like this -

    self.gui.append((GUI_BUTTON,{'label':label,'ref':ref,
        'enabled':enabled,'default':default}))

and the client code looks like this -

    MyButton(self.panel,data['label'],data['ref'],
        data['enabled'],data['default'])

Performance and readability are pretty much identical. The second
method results in a slightly longer string.

I am curious. Why is xml frowned upon? Is my new method ok, or is there
a better way?

Frank Millman




More information about the Python-list mailing list