FAQ
I have looked upon various object serialization de-serialization
techniques.
(shelve, pickle, anydbm, custom xml format etc.) What I personally
feel that instead of all these
methods for saving the objects it would be easier to save the data as
python scripts itself.
In this case, loading the data is merely to run the script in the
context itself.
Need some expert advice and pointers here. Is there any thing (module,
script, doc, article)
helpful out there for the concern?

Prashant

Python 2.6.2
Win XP 32

Search Discussions

  • Diez B. Roggisch at Nov 13, 2009 at 5:33 pm

    King schrieb:
    I have looked upon various object serialization de-serialization
    techniques.
    (shelve, pickle, anydbm, custom xml format etc.) What I personally
    feel that instead of all these
    methods for saving the objects it would be easier to save the data as
    python scripts itself.
    In this case, loading the data is merely to run the script in the
    context itself.
    Need some expert advice and pointers here. Is there any thing (module,
    script, doc, article)
    helpful out there for the concern?
    Why is it easier than the above mentioned - they are *there* (except the
    custom xml), and just can be used. What don't they do you want to do?

    Other than that, and even security issues put aside, I don't see much
    difference between pickle and python code, except the latter being more
    verbose. Which suits humans, but other than that has no advantage.

    Diez
  • King at Nov 13, 2009 at 6:26 pm

    Why is it easier than the above mentioned - they are *there* (except the
    custom xml), and just can be used. What don't they do you want to do?

    Other than that, and even security issues put aside, I don't see much
    difference between pickle and python code, except the latter being more
    verbose. Which suits humans, but other than that has no advantage.

    Diez
    My application is PyQt based and objects that I am trying to save are
    couple of QGraphicsItem instances. You can't save instances of
    QGraphicsItem
    using pickle or shelve.
    Custom xml format would be a real pain as you have to write code for
    writing/reading both.

    I am aware of security issue but over all there are only 5 statements
    I have to use to get the entire
    information back. I can do syntax checking and other stuff before I
    should execute the script.

    Another reason is that data should be in human readable form.

    Prashant

    Python 2.6.2
    Win XP 32
  • Chris Rebert at Nov 13, 2009 at 6:45 pm

    On Fri, Nov 13, 2009 at 10:26 AM, King wrote:
    Why is it easier than the above mentioned - they are *there* (except the
    custom xml), and just can be used. What don't they do you want to do?

    Other than that, and even security issues put aside, I don't see much
    difference between pickle and python code, except the latter being more
    verbose. Which suits humans, but other than that has no advantage.

    Diez
    My application is PyQt based and objects that I am trying to save are
    couple of QGraphicsItem instances. You can't save instances of
    QGraphicsItem
    using pickle or shelve.
    Custom xml format would be a real pain as you have to write code for
    writing/reading both.

    I am aware of security issue but over all there are only 5 statements
    I have to use to get the entire
    information back. I can do syntax checking and other stuff before I
    should execute the script.

    Another reason is that data should be in human readable form.
    Did you consider the `json` module? JSON is almost identical to Python
    literal syntax.
    http://docs.python.org/library/json.html

    Cheers,
    Chris
  • J Kenneth King at Nov 16, 2009 at 1:27 pm

    King <animator333 at gmail.com> writes:

    Why is it easier than the above mentioned - they are *there* (except the
    custom xml), and just can be used. What don't they do you want to do?

    Other than that, and even security issues put aside, I don't see much
    difference between pickle and python code, except the latter being more
    verbose. Which suits humans, but other than that has no advantage.

    Diez
    My application is PyQt based and objects that I am trying to save are
    couple of QGraphicsItem instances. You can't save instances of
    QGraphicsItem
    using pickle or shelve.
    Custom xml format would be a real pain as you have to write code for
    writing/reading both.

    I am aware of security issue but over all there are only 5 statements
    I have to use to get the entire
    information back. I can do syntax checking and other stuff before I
    should execute the script.

    Another reason is that data should be in human readable form.

    Prashant

    Python 2.6.2
    Win XP 32
    Pickling should work just fine. If you cannot pickle the class with the
    default pickler, you can hook into the pickler protocol to tell pickle
    how to pickle instances of the class. Failing that you can write your
    own pickler class for handling the special case.

    Python scripts aren't really a good data format. They're not structured
    in a way that would be easy to parse and extract information from in a
    non-python context without a lot of work.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedNov 13, '09 at 4:46p
activeNov 16, '09 at 1:27p
posts5
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase