Name
compile
Synopsis
compile(string
,filename
,kind
)
Compiles a string and returns a code object usable by
exec
or eval
.
compile
raises SyntaxError
when
string
is not syntactically valid Python.
When string
is a multiline compound
statement, the last character must be '\n
‘.
kind
must be 'eval
'
when string
is an expression and the
result is meant for eval
, otherwise
kind
must be 'exec
‘.
filename
must be a string, and is used
only in error messages (if and when errors occur). See also
eval in this section and Section 13.1.
Get Python in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.