Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python compile() Function

Python compile() Function

Python built-in function Python built-in function


Description

The compile() function compiles a string into byte code.

Syntax

The syntax of the compile() method is as follows:


compile(source, filename, mode[, flags[, dont_inherit]])

Parameters

Return Value

Returns the result of expression execution.


Example

The following examples show the use of the compile function:

str

=

"

for i in range(0,10): print(i)

"

c

=

compile

(

str

,

'

'

,

'

exec

'

)

Compile into a byte code object

c

<

code

object

<

module

at

0

x10141e0b0

,

file

"

"

,

line

1

exec

(

c

)

0

1

2

3

4

5

6

7

8

9

str

=

"

3 * 4 + 5

"

a

=

compile

(

str

,

'

'

,

'

eval

'

)

eval

(

a

)

17

Python built-in function Python built-in function