From 616cef56590b535355dca6641206486b45e78b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Wed, 30 Jan 2019 05:09:33 +0100 Subject: [PATCH] Pickle --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6e06904..807a2e3 100644 --- a/README.md +++ b/README.md @@ -952,10 +952,11 @@ Pickle ------ ```python >>> import pickle ->>> favorite_color = {'lion': 'yellow', 'kitty': 'red'} ->>> pickle.dump(favorite_color, open('data.p', 'wb')) ->>> pickle.load(open('data.p', 'rb')) -{'lion': 'yellow', 'kitty': 'red'} +>>> P = collections.namedtuple('P', 'x y') +>>> points = [P(0, 0), P(1, 1), P(2, 2)] +>>> pickle.dump(points, open('points.p', 'wb')) +>>> pickle.load(open('points.p', 'rb')) +[P(x=0, y=0), P(x=1, y=1), P(x=2, y=2)] ```