Pickle and wx.TextCtrl
gagsl-py2 at yahoo.com.ar
Fri Jul 18 01:44:28 CEST 2008
En Thu, 17 Jul 2008 09:40:29 -0300, <DWebre at dotd.la.gov> escribi�:
> The way you read the file is rather strange -mixing calls to readline and
> pickle.load- I'd write the data using pickle.dump calls *only* and then
> read it using pickle.load calls *only*.
> I used 13.1.7 Example of the Python Library Referencebut. Got an error
> message when I did not have the readline() statement.
The example doesn't have any readline(). Make sure you open the file in
binary format ('wb' or 'rb').
If you have a list of objects: just write the list. It takes a single call
to pickle.dump(), and later, a single call to picle.load()
If you have too many objects and don't want to save/load all of them at
once, write them one at a time using pickle.dump(element, output_file,
-1), ending with a sentinel value (e.g. None): pickle.dump(None, ...)
You may read them again using something like this:
pfile = open(..., 'rb')
element = pickle.load(pfile)
if element is None: break
Ensure that you can save and load your data using a simple script,
*before* writing the GUI.
More information about the Python-list