-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctions_compile().py
38 lines (28 loc) · 1.43 KB
/
Functions_compile().py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Python compile() Function
# Example
# Compile text as code, and the execute it:
x = compile('print(55)', 'test', 'eval')
exec(x)
# Definition and Usage
# The compile() function returns the specified source as a code object, ready to be executed.
# Syntax
# compile(source, filename, mode, flag, dont_inherit, optimize)
# Parameter Values
# Parameter Description
# source Required. The source to compile, can be a String, a Bytes object, or an AST object
# filename Required. The name of the file that the source comes from. If the source does not come from a file, you can write whatever you like
# mode Required. Legal values:
# eval - if the source is a single expression
# exec - if the source is a block of statements
# single - if the source is a single interactive statement
# flags Optional. How to compile the source. Default 0
# dont-inherit Optional. How to compile the source. Default False
# optimize Optional. Defines the optimization level of the compiler. Default -1
# More Examples
# Example
# Compile more than one statement, and the execute it:
x = compile('print(55)\nprint(88)', 'test', 'exec')
exec(x)
# Related Pages
# The eval() Function
# The exec() Function