Clueless with cPickle

Jp Calderone exarkun at divmod.com
Sun May 8 17:33:52 EDT 2005


On Sun, 08 May 2005 21:27:35 GMT, les <ordnancemarine at yahoo.com> wrote:
>I am working on a homework assignment and trying to use cPickle to store
>the answers from questor.py I believe I have the syntax correct but am not
>sure if I am placing everything where it needs to be.  Any help would be
>greatly appreciated.  When I attempt to run what I have I end up with the
>following:
>
>Traceback (most recent call last):
>  File "/home/les/workspace/Module 2/questor.py", line 18, in ?
>    f = file(questorlistfile)
>NameError: name 'questorlistfile' is not defined
>
>I thought that I had defined questorlistfile on the 4th line below
>
># define some constants for future use
>
>import cPickle as p
>#import pickle as p
>
>questorfile = 'questor.data' # the name of the file where we will 
 ^^^^^^^^^^^

  Note this variable name

>                             # store the object
>
>questorlist = []
>
># Write to the file
>f = file(questorfile, 'w')
>p.dump(questorlist, f) # dump the object to a file
>f.close()
>
>del questorlist # remove the shoplist
>
># Read back from the storage
>f = file(questorlistfile)
          ^^^^^^^^^^^^^^^

  Compare it with this variable name.

> [snip]

  Jp



More information about the Python-list mailing list