Perl XML::Simple and Data::Dumper - exists in Python?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Miguel Manso

    #1

    Perl XML::Simple and Data::Dumper - exists in Python?

    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.

    2) Perl's XML::Simple

    It maps a XML file into a Perl data structure.

    Does Python have something like these two tools? I've been googling
    before posting this and didn't find anything.

    Thanks for the help.

    --
    Miguel Manso <mmanso@opalaco nsult.com>
  • Wallace Owen

    #2
    Re: Perl XML::Simple and Data::Dumper - exists in Python?

    Miguel Manso wrote:[color=blue]
    > 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.[/color]

    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:
    [color=blue][color=green][color=darkred]
    >>> lst = ["one", "two", (3, 4.56), 1]
    >>> print lst[/color][/color][/color]
    ['one', 'two', (3, 4.5599999999999 996), 1][color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]
    [color=blue]
    >
    > 2) Perl's XML::Simple
    >
    > It maps a XML file into a Perl data structure.[/color]

    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.
    [color=blue]
    >
    > Does Python have something like these two tools? I've been googling
    > before posting this and didn't find anything.[/color]

    Do your searches at python.org.


    // Wally

    Comment

    Working...