3 # Print python code that reconstructs a variable.
4 # This only works in certain cases.
7 # - ints and floats (except NaNs and other weird things)
9 # - compounds and lists, provided it works for all their elements
10 # - imported modules, provided their name is the module name
12 # It works for top-level dictionaries but not for dictionaries
13 # contained in other objects (could be made to work with some hassle
16 # It does not work for functions (all sorts), classes, class objects,
19 # Finally, objects referenced by more than one name or contained in more
20 # than one other object lose their sharing property (this is bad for
21 # strings used as exception identifiers, for instance).
23 # Dump a whole symbol table
26 for key
in dict.keys():
27 dumpvar(key
, dict[key
])
29 # Dump a single variable
38 if not printable(item
):
40 print name
, '[', `key`
, '] =', `item`
41 elif t
in (type(''), type(0), type(0.0), type([]), type(())):
46 print 'import', name
, '#', x
48 print '#', name
, '=', x
50 # check if a value is printable in a way that can be read back with input()
54 if t
in (type(''), type(0), type(0.0)):
56 if t
in (type([]), type(())):
58 if not printable(item
):