Perl XML::Simple and Data::Dumper - exists in Python?
Wallace Owen
owen at metamachine.com
Thu Jun 15 00:59:58 EDT 2006
Miguel Manso wrote:
> Hi there,
>
> I'm a Perl programmer trying to get into Python. I've been reading some
> documentation and I've choosed Python has being the "next step" to give.
>
> Can you point me out to Python solutions for:
>
> 1) Perl's Data::Dumper
>
> It dumps any perl variable to the stdout in a "readable" way.
All Python objects support reflection and can be serialized to a data
stream. There's about four ways to do it (Kinda perl-like in that
regard, but typically for a particular application there's one obvious
right choice). You control the way your objects appear as strings, by
defining a __str__ member function that'll be invoked if the user does:
% print str(yourObject)
You can print any builtin type with just:
>>> lst = ["one", "two", (3, 4.56), 1]
>>> print lst
['one', 'two', (3, 4.5599999999999996), 1]
>>>
>
> 2) Perl's XML::Simple
>
> It maps a XML file into a Perl data structure.
Python's got a Document Object Model lib that essentially maps an XML
file to objects that have built-in-type behavior - you can treat a
NodeList object as a python list, indexing into it, iterating over it's
contents, etc.
It's also got SAX and expat bindings.
>
> Does Python have something like these two tools? I've been googling
> before posting this and didn't find anything.
Do your searches at python.org.
// Wally
More information about the Python-list
mailing list