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

codeop.Compile

Prev: codeop.CommandCompiler | Up: codeop | Next: codeop.compile_command
Rel: codeop.CommandCompiler, codeop.compile_command
Ref: docs.python.org — codeop.Compile
Tags: #public #python3 #stdlib #codeop


Import

import codeop
from codeop import Compile

Signature & Overview

codeop.Compile()

Instances of this class behave much like the built-in compile function, but if one is used to compile text containing a future statement, it "remembers" and compiles all subsequent program texts

Usage

import codeop

c = codeop.Compile()
code_obj = c("1 + 1", "<mem>", "eval")
assert eval(code_obj) == 2

Gotchas

REPL Inspect

from codeop import Compile
help(Compile)

Linked from

Related notes