Ron_Adam <[EMAIL PROTECTED]> writes:
> Here's yet another way to do it, but it has some limitations as well.
>
> import pickle
> def pickle_it(filename, obj, commands):
>     try:
>         f = open(filename, 'r')    
>         obj = pickle.load(f)
>         f.close()
>     except IOError:
>         pass  
>     for i in commands:
>         i[0](i[1])
>     f = open(filename, 'w')
>     pickle.dump(obj, f)
>     f.close()
>  
> file = 'filename'
> L = []
>
> opps = [ (L.append,'more data'),
>          (L.append,'even more data') ]
> pickle_it(file, L, opps)

Um - it doesn't look like this will work. You pass L in as the "obj"
paremeter, and then it gets changed to the results of a
pickle.load. However, you call L.append in the for loop, so the data
will be appended to L, not obj. You'll lose an list elements that were
in the pickle.

   <mike
-- 
Mike Meyer <[EMAIL PROTECTED]>                  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to