importlib.util.cache_from_source(path, debug_override=None, *, optimization=None)
Return the PEP 3147/PEP 488 path to the byte-compiled file associated with the source path. For example, if path is /foo/bar/baz.py
the return value would be /foo/bar/__pycache__/baz.cpython-32.pyc
for Python 3.2. The cpython-32
string comes from the current magic tag (see get_tag()
; if sys.implementation.cache_tag
is not defined then NotImplementedError
will be raised).
The optimization parameter is used to specify the optimization level of the bytecode file. An empty string represents no optimization, so /foo/bar/baz.py
with an optimization of ''
will result in a bytecode path of /foo/bar/__pycache__/baz.cpython-32.pyc
. None
causes the interpter’s optimization level to be used. Any other value’s string representation being used, so /foo/bar/baz.py
with an optimization of 2
will lead to the bytecode path of /foo/bar/__pycache__/baz.cpython-32.opt-2.pyc
. The string representation of optimization can only be alphanumeric, else ValueError
is raised.
The debug_override parameter is deprecated and can be used to override the system’s value for __debug__
. A True
value is the equivalent of setting optimization to the empty string. A False
value is the same as setting optimization to 1
. If both debug_override an optimization are not None
then TypeError
is raised.
New in version 3.4.
Changed in version 3.5: The optimization parameter was added and the debug_override parameter was deprecated.
Please login to continue.