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

Python __import__() Function

Python importThe () function

Python built-in function Python built-in function


Description

import() The function is used to dynamically load classes and functions.

If a module changes frequently, you can use import() to load it dynamically.

Syntax

import Syntax:


__import__(name[, globals[, locals[, fromlist[, level]]]])

Parameter Description:

Return Value

Returns a list of tuples.

Example

The following example shows import Usage:

Code in the a.py file:

#!/usr/bin/env python

#encoding: utf-8

import

os

print

(

'

In the a.py file %s

'

%

id

(

os

)

)

Code in the test.py file:

#!/usr/bin/env python

#encoding: utf-8

import

sys

import

(

'

a

'

)

Import the a.py module

Execute the test.py file; the output is:


在 a.py 文件中 4394716136

Python built-in function Python built-in function