小白教程
所有教程
关于
Search
172.69.59.18
172.69.59.18
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python func import”的源代码
本页内容
上一节:
Python3_func_reversed
下一节:
Python_func_complex
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:__import__()}}[[Category:python3 built in functions|59]] = Python __import__() 函数 = [[python built in functions|Python 内置函数]] == 描述 == '''__import__()''' 函数用于动态加载类和函数 。 如果一个模块经常变化就可以使用 __import__() 来动态载入。 == 语法 == __import__ 语法: <sample title="" desc="" lang="python" hererun="1"> __import__(name[, globals[, locals[, fromlist[, level]]]]) </sample> 参数说明: * name -- 模块名 == 返回值 == 返回元组列表。 以下实例展示了 __import__ 的使用方法: == a.py 文件代码: == <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/env python #encoding: utf-8 import os print ('在 a.py 文件中 %s' % id(os)) </sample> == test.py 文件代码: == <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/env python #encoding: utf-8 import sys __import__('a') # 导入 a.py 模块 </sample> 执行 test.py 文件,输出结果为: <sample title="" desc="" lang="python" hererun="1"> 在 a.py 文件中 4394716136 </sample> [[python built in functions|Python 内置函数]]
返回至“
Python func import
”。
上一节:
Python3_func_reversed
下一节:
Python_func_complex