'\ \ ] \ ( \ \ \ python default protocol= =binary pickle dumps([ ]protocol= '(lp \nl \nal \nal \na ascii protocol but still bytesthis implies that files used to store pickled objects must always be opened in binary mode in python xsince text files use str strings to represent datanot bytes--the dump call simply attempts to write the pickle string to an open output filepickle dump([ ]open('temp'' ')typeerrormust be strnot bytes text files fail on bytesdespite protocol value pickle dump([ ]open('temp'' ')protocol= typeerrormust be strnot bytes pickle dump([ ]open('temp''wb')always use binary in open('temp'' 'read('\ ac\ ] \ ( \ \ \ this worksbut just by luck notice the last result here didn' issue an error in text mode only because the stored binary data was compatible with the windows platform' utf- default decoderthis was really just luck (and in factthis command failed when printing in older pythonsand may fail on other platformsbecause pickle data is not generally decodable unicode textthe same rule holds on input--correct usage in requires always both writing and reading pickle data in binary modeswhether unpickling or notpickle dump([ ]open('temp''wb')pickle load(open('temp''rb')[ open('temp''rb'read( '\ \ ] \ ( \ \ \ in python xwe can get by with text-mode files for pickled dataas long as the protocol is level (the default in xand we use text mode consistently to convert line endsc:\codec:\python \python import pickle pickle dumps([ ]'(lp \ni \nai \nai \na python default= =ascii pickle dumps([ ]protocol= '] \ ( \ \ \ pickle dump([ ]open('temp'' ')pickle load(open('temp')[ open('temp'read('(lp \ni \nai \nai \na unicode and byte strings text mode works in