another tricky problem with unicode strings is that there might be multiple representations of the same unicode string for examplethe character + ( )might be fully composed as single character + or decomposed into multicharacter sequence + + ( ~if consistent processing of unicode strings is an issueuse the unicodedata normalize(function to ensure consistent character representation for exampleunicodedata normalize('nfc'swill make sure that all characters in are fully composed and not represented as sequence of combining characters further details about the unicode character database and the unicodedata module can be found in "strings and text handling object persistence and the pickle module finallyit' often necessary to save and restore the contents of an object to file one approach to this problem is to write pair of functions that simply read and write data from file in special format an alternative approach is to use the pickle and shelve modules the pickle module serializes an object into stream of bytes that can be written to file and later restored the interface to pickle is simpleconsisting of dump(and load(operation for examplethe following code writes an object to fileimport pickle obj someobject( open(filename,'wb'pickle dump(objff close(save object on to restore the objectyou can use the following codeimport pickle open(filename,'rb'obj pickle load(frestore the object close( sequence of objects can be saved by issuing series of dump(operations one after the other to restore these objectssimply use similar sequence of load(operations the shelve module is similar to pickle but saves objects in dictionary-like databaseimport shelve obj someobject(db shelve open("filename"db['key'obj obj db['key'db close(open shelve save object in the shelve retrieve it close the shelve although the object created by shelve looks like dictionaryit also has restrictions firstthe keys must be strings secondthe values stored in shelf must be compatible with pickle most python objects will workbut special-purpose objects such as files and network connections maintain an internal state that cannot be saved and restored in this manner the data format used by pickle is specific to python howeverthe format has evolved several times over python versions the choice of protocol can be selected using an optional protocol parameter to the pickle dump(objfileprotocoloperation lib fl ff