python - Why doesn't appending binary pickles work? -


I know that it is not really how to use a pickle module, but I would have thought that it would work . I have been using Python 3.1.2

Here is the background code:

  Import Stick FILEPATH = '/ tmp / tempfile' Category HistoryFile (): " "" Each store in the continuous store a history file should be a different python object Usually, pickle is used to create a file for each object, but here, I have a file to validate the sequence "+" def Trying to use write mode mode (Self, OBJ): "What is the return or not the expression is the right pythonic object" "Returns true def add (self, oBJ): if self.validate (obj): Open with (FILEPATH, mode = 'BA') F As: # attached, do not write f.write (pickle.dumps (obj)) Other: "was not valid" Def unpack (self): Go through each line in the "" "file and call each dragon object A list, which is returned as "open" (FILEPATH, mode = 'br') to "lst = []": # The problem should be here , Does not it move through the file? L in f: lst.append (pickle.loads (l)) back  

Now, when I run it, this is only the first object Which is given in the class

  if __name__ == '__main__': l = history file () l.ed ('a') l.ed ('dfsdfs') l .ad (("DFDKFJDF", 'Error', 'Cvcvcxvx']) Print (L.Pack ()) # prints the first item only, 'A'!  

Is it looking at the initial EOF? It is possible that it is possible to do an ASCI applying only? (In this case, why do I have to do the mode = 'ba'?) Is that a very easy way to do this?

Why would you think that binary pickling will produce a pickle? Piking gives you many items (and returning) after each other, so it is obvious that this should be an "self-termination" sorting format. Forget the lines and take them back! For example:

  & gt; & Gt; & Gt; Import Pickles & gt; & Gt; & Gt; Import cStringIO & gt; & Gt; & Gt; S = cStringIO.StringIO ()> & gt; & Gt; & Gt; Pickle.dump (23, s)> gt; & Gt; & Gt; Pickle.dump (45, s) & gt; & Gt; & Gt; S. Sec (0) >> gt; & Gt; Pickle.load (s) 23 & gt; & Gt; & Gt; Pickle.load (s) 45 & gt; & Gt; & Gt; Pickle.load (s) traceback (the most recent call final): ... EOFError & gt; & Gt; & Gt;  

Just grab the EOFError to tell you when you're unplicking.


Comments