modebinary mode is always required in python xbecause the pickler creates and uses bytes string objectand these objects imply binarymode files (text-mode files imply str strings in xin earlier pythons it' ok to use text-mode files for protocol (the defaultwhich creates ascii text)as long as text mode is used consistentlyhigher protocols require binary-mode files python ' default protocol is (binary)but it creates bytes even for protocol see and python' library manualor reference books for more details on and examples of pickled data python also has cpickle modulewhich is an optimized version of pickle that can be imported directly for speed python renames this module _pickle and uses it automatically in pickle--scripts simply import pickle and let python optimize itself storing python objects in json format the prior section' pickle module translates nearly arbitrary python objects to proprietary format developed specifically for pythonand honed for performance over many years json is newer and emerging data interchange formatwhich is both programming-language-neutral and supported by variety of systems mongodbfor instancestores data in json document database (using binary json formatjson does not support as broad range of python object types as picklebut its portability is an advantage in some contextsand it represents another way to serialize specific category of python objects for storage and transmission moreoverbecause json is so close to python dictionaries and lists in syntaxthe translation to and from python objects is trivialand is automated by the json standard library module for examplea python dictionary with nested structures is very similar to json datathough python' variables and expressions support richer structuring options (any part of the following can be an arbitrary expression in python code)name dict(first='bob'last='smith'rec dict(name=namejob=['dev''mgr']age= rec {'job'['dev''mgr']'name'{'last''smith''first''bob'}'age' the final dictionary format displayed here is valid literal in python codeand almost passes for json when printed as isbut the json module makes the translation official --here translating python objects to and from json serialized string representation in memoryimport json json dumps(rec'{"job"["dev""mgr"]"name"{"last""smith""first""bob"}"age" } json dumps(recs files