Skip to content

Commit

Permalink
Clean up serialize_ast example to use HIGHEST_PROTOCOL for pickling
Browse files Browse the repository at this point in the history
  • Loading branch information
eliben committed Jan 9, 2023
1 parent 4e16079 commit 489d208
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions examples/serialize_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@
parser = c_parser.CParser()
ast = parser.parse(text)

# Since AST nodes use __slots__ for faster attribute access and
# space saving, it needs Pickle's protocol version >= 2.
# The default version is 3 for python 3.x and 1 for python 2.7.
# You can always select the highest available protocol with the -1 argument.

with open('ast', 'wb') as f:
pickle.dump(ast, f, protocol=-1)
pickle.dump(ast, f, protocol=pickle.HIGHEST_PROTOCOL)

# Deserialize.
with open('ast', 'rb') as f:
Expand Down

0 comments on commit 489d208

Please sign in to comment.