3

I saw these two answers about Pickle and cPickle having dealt automatically by python 3, transparent to the user:

How can I know if in python 3, it is using the fast version (cPickle) or not? I want to force it to use cPickle. My main interest is not even on the speed, but on the shorter size of the files, since I am generating files that end up being bigger than 1 GB.

Homero Esmeraldo
  • 1,864
  • 2
  • 18
  • 34

1 Answers1

7

Unless you build your Python binary from source, you almost certainly are using the C extension.

However, if you must be certain, check if the _pickle module can be imported:

>>> import _pickle

The pickle module imports _pickle and only if that fails with an ImportError would it be using the pure-Python implementation.

Just to be explicit: what was called cPickle in Python 2 has been renamed to _pickle and is imported transparently, you don't have to do anything explicit to make use of it. That there was a split between pickle and cPickle in Python 2 was just plain confusing.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343