Pickling dynamically generated classes

Discussion in 'Python' started by George Sakkis, Jan 26, 2008.

  1. The Fine Manual mentions that pickle works for classes that are
    defined at the top level of a module. Is there a way to extend this
    behavior so that I can pickle and unpickle instances of dynamically
    generated classes ?

    Longer version: I have a function RecordTypeFactory(fields, ...) that
    dynamically generates and caches a record-like class based on the
    passed fields and other info (or returns the cached class if it has
    been created before). Although I am able to pickle instances of the
    various generated classes (records) by writing the gen. class in
    globals(), I cannot unpickle them from a different process unless
    RecordTypeFactory is called with the same arguments so that "the same"
    class is generated in the other process as well. Essentially what I'm
    missing is a hook to call RecordTypeFactory with the same fields when
    an instance of the gen. class is to be unpickled.

    George
     
    George Sakkis, Jan 26, 2008
    #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. Dave Brueck
    Replies:
    0
    Views:
    316
    Dave Brueck
    Feb 10, 2004
  2. Dave Brueck
    Replies:
    0
    Views:
    439
    Dave Brueck
    Feb 10, 2004
  3. Daniel Bickett
    Replies:
    2
    Views:
    304
    Daniel Bickett
    Feb 6, 2005
  4. Nicolas M. Thiéry

    Pickling classes (not class instances)

    Nicolas M. Thiéry, Jan 10, 2009, in forum: Python
    Replies:
    2
    Views:
    359
    Aaron Brady
    Feb 14, 2009
  5. lars van gemerden
    Replies:
    10
    Views:
    611
    lars van gemerden
    Jan 3, 2012
Loading...

Share This Page