Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
1db94084
Commit
1db94084
authored
Jun 18, 1999
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Relocating file to Lib/lib-old.
parent
ffe3cb95
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
63 deletions
+0
-63
Lib/dump.py
Lib/dump.py
+0
-63
No files found.
Lib/dump.py
deleted
100644 → 0
View file @
ffe3cb95
# Module 'dump'
#
# Print python code that reconstructs a variable.
# This only works in certain cases.
#
# It works fine for:
# - ints and floats (except NaNs and other weird things)
# - strings
# - compounds and lists, provided it works for all their elements
# - imported modules, provided their name is the module name
#
# It works for top-level dictionaries but not for dictionaries
# contained in other objects (could be made to work with some hassle
# though).
#
# It does not work for functions (all sorts), classes, class objects,
# windows, files etc.
#
# Finally, objects referenced by more than one name or contained in more
# than one other object lose their sharing property (this is bad for
# strings used as exception identifiers, for instance).
# Dump a whole symbol table
#
def
dumpsymtab
(
dict
):
for
key
in
dict
.
keys
():
dumpvar
(
key
,
dict
[
key
])
# Dump a single variable
#
def
dumpvar
(
name
,
x
):
import
sys
t
=
type
(
x
)
if
t
==
type
({}):
print
name
,
'= {}'
for
key
in
x
.
keys
():
item
=
x
[
key
]
if
not
printable
(
item
):
print
'#'
,
print
name
,
'['
,
`key`
,
'] ='
,
`item`
elif
t
in
(
type
(
''
),
type
(
0
),
type
(
0.0
),
type
([]),
type
(())):
if
not
printable
(
x
):
print
'#'
,
print
name
,
'='
,
`x`
elif
t
==
type
(
sys
):
print
'import'
,
name
,
'#'
,
x
else
:
print
'#'
,
name
,
'='
,
x
# check if a value is printable in a way that can be read back with input()
#
def
printable
(
x
):
t
=
type
(
x
)
if
t
in
(
type
(
''
),
type
(
0
),
type
(
0.0
)):
return
1
if
t
in
(
type
([]),
type
(())):
for
item
in
x
:
if
not
printable
(
item
):
return
0
return
1
if
x
==
{}:
return
1
return
0
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment