How to enable a pure Python module instead of a C accelerated version for a stdlib module such as datetime -
some stdlib modules (such datetime
, decimal
, io
) have both c , pure python implementations e.g., see pep 399 -- pure python/c accelerator module compatibility requirements.
it might desirable disable c accelerated version.
for decimal
, io
modules can import _pydecimal
, _pyio
modules directly. how access pure python datetime
implementation?
the c accelarated version (_datetime
) enabled in datetime.py
using from _datetime import *
, therefore enough cause importerror , reload datetime module in case has been imported earlier:
import importlib import sys sys.modules['_datetime'] = none # cause importerror datetime = importlib.reload(importlib.import_module('datetime'))
test:
>>> datetime.timedelta(1<<30) traceback (most recent call last): file "<stdin>", line 1, in <module> file "/usr/lib/python3.4/datetime.py", line 430, in __new__ raise overflowerror("timedelta # of days large: %d" % d) overflowerror: timedelta # of days large: 1073741824
the traceback shows pure python version used.