Pickle vs. eval for deeply nested objects

Discussion in 'Python' started by Edward C. Jones, Feb 18, 2004.

  1. Here is a little piece of Python that produces a deeply nested tuple:

    deep = 'x'
    for i in range(50):
    deep = (deep,)

    This is a perfectly ordinary Python object. It can be pickled and unpickled:

    s = cPickle.dumps(deep)
    deep2 = cPickle.loads(s)

    But "eval" (and "compiler.parse") fail on "str(deep)" because some stack
    gets too big. Is there some deep reason why cPickle can reconstruct
    "deep" from a string while eval can't?
     
    Edward C. Jones, Feb 18, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ori Y
    Replies:
    1
    Views:
    415
    Bob Ippolito
    Feb 28, 2004
  2. Kirk Strauser
    Replies:
    1
    Views:
    318
    Kirk Strauser
    Jun 11, 2004
  3. Michele Simionato
    Replies:
    2
    Views:
    1,934
    Michele Simionato
    May 23, 2008
  4. Gerald Britton
    Replies:
    3
    Views:
    265
    Steven D'Aprano
    Jan 30, 2011
  5. Stephen Hansen
    Replies:
    4
    Views:
    266
    Stephen Hansen
    Jan 31, 2011
Loading...

Share This Page