compileall.compile_file
Prev: compileall.compile_dir | Up: compileall | Next: compileall.compile_path
Rel: compileall.compile_dir, compileall.compile_path
Ref: docs.python.org — compileall.compile_file
Tags: #public #python3 #stdlib #compileall
Import
import compileall
from compileall import compile_file
Signature & Overview
compileall.compile_file(fullname, ddir=None, force=False, rx=None, quiet=0, legacy=False, optimize=-1, invalidation_mode=None, *, stripdir=None, prependdir=None, limit_sl_dest=None, hardlink_dupes=False)
Byte-compile one file.
Usage
import compileall
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as tmp:
p = Path(tmp) / "one.py"
p.write_text("y = 2\n", encoding="utf-8")
assert compileall.compile_file(str(p), quiet=1) is True
Gotchas
- Skips up-to-date
.pycfiles unlessforce=True.
REPL Inspect
from compileall import compile_file
help(compile_file)
Linked from
Related notes
- tuts/python3/stdlib_module/compileall/compile_dir Linked here; links to this page; shared tags: #compileall, #stdlib
- tuts/python3/stdlib_module/compileall/compile_path Linked here; links to this page; shared tags: #compileall, #stdlib
- tuts/python3/stdlib_module/compileall Linked here; links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib
- tuts/c/stdlib/ctype shared tags: #stdlib
- tuts/c/stdlib/ctype/isalpha shared tags: #stdlib
- tuts/c/stdlib/ctype/isdigit shared tags: #stdlib