using marshal module

Christine Davis c.davis at actrix.co.nz
Tue Feb 1 23:17:08 EST 2000


Hi All,

I am new to python (but old(er) to C++);  and trying to get a script to
work.  What it is meant to do, is reads in a file,  config.db and then
changes the values of one of the fields, and write the revised contents
back.  if I call dump(<array where file contents loaded to>, <name of file
pointer>) no change seems to take place.  (The field isn't changed,  nor
does the field get concatenated at the end.

I have this feeling I may be missing out something important, but silly.

Cheers,
Christine


Here is the piece of broken code:

# open the file
fp = open(filename)
datastuff = marshal.load(fp)

# change the field
datastuff['field'] = 'new string of stuff'

# "write it back to the file"
# also tried "marshal.dump(datastuff, fp)" which didn't work either
marshal.dump(datastuff['field'], fp)

# close the file
fp.close()





More information about the Python-list mailing list