您的位置:首页 > 编程语言 > Python开发

python之模块导入和重载

2016-02-05 21:37 453 查看

模块导入和重载

模块导入通过import语句实现,但是在同一次会话中只运行一次。

若想要再次运行文件,调用imp标准库中的reload函数:

>>> from imp import reload
>>> reload(script1)

Details are shown in the following example:

create a module named 'myfile.py':

title = "The Meaning of Life"

title is the attribute of 'myfile.py'.

通过属性引用:

>>> import myfile
>>> print(myfile.title)
The Meaning of Life

或者以变量title饮用导入字符串:

>>> from myfile import title
>>> print(title)
The Meaning of Life
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: