From 75a29a1fa6f7761a8e370e41bcbaa51b60f2b66f Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Wed, 2 Sep 2009 15:07:51 -0400 Subject: [PATCH] equality / identity comparison --- serializing.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/serializing.html b/serializing.html index a26df2c..26e28a4 100644 --- a/serializing.html +++ b/serializing.html @@ -148,7 +148,9 @@ NameError: name 'entry' is not defined ... >>> entry2 == entry True ->>> entry2['tags'] +>>> entry2 is entry +False +>>> entry2['tags'] ('diveintopython', 'docbook', 'html') >>> entry2['internal_id'] b'\xDE\xD5\xB4\xF8' @@ -157,6 +159,7 @@ NameError: name 'entry' is not defined
  • Open the entry.pickle file.
  • Load the serialized data into a new variable, entry2.
  • Python confirms that the two dictionaries, entry and entry2, are equal. In this shell, you built entry from the ground up, starting with an empty dictionary and manually assigning values to specific keys. You serialized this dictionary and stored it in the entry.pickle file. Now you’ve read the serialized data from that file and created a perfect replica of the original data structure. +
  • Equality is not the same as identity. I said you’ve created a perfect replica of the original data structure, which is true. But it’s still a copy.
  • For reasons that will become clear later in this chapter, I want to point out that the value of the 'tags' key is a tuple, and the value of the 'internal_id' key is a bytes object.