Most objects can be saved with pickle module. The module serializes
objects to strings by storing *the names* of classes of objects and real
data (usually, their __dict__ dictionaries.) On restoring (unpickling) the
loader instantiates objects (it know their class names, right?) and put the
data back.
  But code objects are very special objects in Python. Pickle doesn't save
it, and you too - you better not meddle with them.

Thanks, I think I will go the "getattr" way.