On this page
  1. compileall.compile_file
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

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

REPL Inspect

from compileall import compile_file
help(compile_file)

Linked from

Related notes