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
相关文章推荐
- [Leetcode]201. Bitwise AND of Numbers Range @python
- 最简单的python命令解析器
- [Leetcode]188. Best Time to Buy and Sell Stock IV@python
- NumPy基础(一)
- Python lambda和reduce函数
- Python教程学习简记4--Python 迭代(iteration)
- 《Python核心编程》第四章:Python 对象
- 《Python核心编程》第三章:Python基础
- 《Python核心编程》第二章:Python起步
- Python教程学习简记3--Python 切片
- 如何让python程序运行得更快
- python文件读写的小笔记
- python小爬虫
- 《Python核心编程》第一章:欢迎来到Python世界!
- Python笔记:使用pywin32处理excel文件
- python35
- 迭代器
- [Leetcode] 179. Largest Number @python
- python 11期 第八天
- [Leetcode]174. Dungeon Game @python