Re: Pickle and wx.TextCtrl

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gabriel Genellina

    Re: Pickle and wx.TextCtrl

    En Thu, 17 Jul 2008 09:40:29 -0300, <DWebre@dotd.la .govescribi�:
    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(ele ment, output_file,
    -1), ending with a sentinel value (e.g. None): pickle.dump(Non e, ...)
    You may read them again using something like this:

    pfile = open(..., 'rb')
    while True:
    element = pickle.load(pfi le)
    if element is None: break
    do_something_wi th(element)
    pfile.close()

    Ensure that you can save and load your data using a simple script,
    *before* writing the GUI.

    --
    Gabriel Genellina

Working...