About 32,100 results
Open links in new tab
  1. How can I use pickle to save a dict (or any other Python object)?

    For example, replacing the second line with these lines: ... pickle: A Python serialization format (read ...

  2. pickle - Understanding Pickling in Python - Stack Overflow

    Oct 4, 2019 · The pickle module implements a fundamental, but powerful algorithm for serializing and de-serializing a Python object structure. Pickling - is the process whereby a Python object hierarchy is converted into a byte stream, and Unpickling - is the inverse operation, whereby a byte stream is converted back into an object hierarchy.

  3. python - Saving and loading objects and using pickle - Stack …

    Historical note: cPickle is a faster implementation of the pickle module in C that will be used automatically in python 3.x. But in python 2.x it cPickle required explicit calls:

  4. python - How to read pickle file? - Stack Overflow

    The following is an example of how you might write and read a pickle file. Note that if you keep appending pickle data to the file, you will need to continue reading from the file until you find what you want or an exception is generated by reaching the end of …

  5. Simple example of use of __setstate__ and __getstate__

    Dec 21, 2009 · import pickle class Foo: def __init__(self, x:int=2, y:int=3): self.x = x self.y = y self.z = x*y def __getstate__(self): # Create a copy of __dict__ to modify values and return; # you could also construct a new dict (or other object) manually out = self.__dict__.copy() out["x"] *= 3 out["y"] *= 10 # You can remove attributes, but note they ...

  6. How to pickle and unpickle to portable string in Python 3

    May 27, 2015 · If space efficiency really matters, you definitely want to use pickle protocol 4 and environb when possible, or maybe even pickle protocol 4 plus bzip. For Windows, I'd test pickle protocol 4 plus bzip plus base64 vs. pickle protocol 0, …

  7. python - What is the difference between pickle and shelve

    Mar 20, 2024 · pickle is for serializing some object (or objects) as a single bytestream in a file.. shelve builds on top of pickle and implements a serialization dictionary where objects are pickled, but associated with a key (some string), so you can load your shelved data file and access your pickled objects via keys.

  8. Common use-cases for pickle in Python - Stack Overflow

    Aug 9, 2010 · 2) sending python data over a TCP connection in a multi-core or distributed system (marshalling) 3) storing python objects in a database. 4) converting an arbitrary python object to a string so that it can be used as a dictionary key (e.g. for caching & memoization).

  9. python - how to use 'pickle' - Stack Overflow

    Jan 7, 2010 · You are able to pickle (meaning, this code works as it should). You just seem to get a result, you don't expect. If you expect the same 'output', try: import pickle a = A() s = pickle.dumps(a) e = pickle.loads(s) print s, pickle.dumps(e) Your example isn't, well, a typical 'pickling' example.

  10. security - Attacking Python's pickle - Stack Overflow

    May 2, 2014 · The python documentation states this: Warning The pickle module is not intended to be secure against erroneous or maliciously constructed data. Never unpickle data received from an untrusted or unauthenticated source. However this is not your case - you accept the input, put it through the regular validation, and then pickle it.

Refresh