particularfile can be an instance of python class that provides the read/write methods ( the expected file-like interfacethis lets you map pickled streams to inmemory objects with classesfor arbitrary use for instancethe io bytesio class in the standard library discussed in provides an interface that maps file calls to and from in-memory byte strings and is an alternative to the pickler' dumps/loads string calls this hook also lets you ship python objects across networkby providing sockets wrapped to look like files in pickle calls at the senderand unpickle calls at the receiver (see "making sockets look like files and streamson page for more detailsin factfor somepickling python objects across trusted network serves as simpler alternative to network transport protocols such as soap and xml-rpcprovided that python is on both ends of the communication (pickled objects are represented with python-specific formatnot with xml textrecent changesin python xpickled objects are always represented as bytesnot strregardless of the protocol level which you request (even the oldest ascii protocol yields bytesbecause of thisfiles used to store pickled python objects should always be opened in binary mode moreoverin an optimized _pickle implementation module is also selected and used automatically if present more on both topics later pickling in action although pickled objects can be shipped in exotic waysin more typical useto pickle an object to flat filewe just open the file in write mode and call the dump functionc:\pp \dbasepython table {' '[ ]' '['spam''eggs']' '{'name':'bob'}import pickle mydb open('dbase''wb'pickle dump(tablemydbnotice the nesting in the object pickled here--the pickler handles arbitrary structures also note that we're using binary mode files herein python xwe really mustbecause the pickled representation of an object is always bytes object in all cases to unpickle later in another session or program runsimply reopen the file and call loadc:\pp \dbasepython import pickle mydb open('dbase''rb'table pickle load(mydbtable {' '[ ]' '{'name''bob'}' '['spam''eggs']pickled objects