python模块2
来源:互联网 发布:纳什生涯总数据 编辑:程序博客网 时间:2024/05/20 12:22
模块的导入。真正的用处在于他们像类一样可以保持自己的作用域。这就意味着所有的类和函数以及赋值后的变量都成为模块的特性。
#D:\hello2.pydef hello(): print "hello word"
>>>import sys>>>sys.path.append('D:\hello2.py')>>>import hello2>>>>hello2.hello()hello word
那么问题来了怎么让我的模块可用呢?
- 将模块放置在合适的位置:
找到**site—packages**目录.将你**.py**文件放进去就可以正常导入啦。
>>>import hello2>>>hello2.hello()hello word
- 告诉解释器去哪里查找需要的模块:
一种方法就是前面所说的sys.path.append(‘你的模块文件’)。
另一种就是标准的实现方法:在PYTHONPATH环境变量中包含模块所在目录。各种操作系统设置环境变量。
包
包含_init_.py与其他程序文件的文件夹。_init_.py标志此文件夹是一个包。drawing/init.py 中包含 shapes.py和colors.py文件。
import drawingimport drawing.shapes #通过drawing.shapes来使用from drawing import colors #可以直接通过colors来使用
0 0
- python 内置模块2
- python模块2
- python模块2
- python(2) 模块
- python模块整理2-sys模块
- python标准模块学习2_______re模块
- Python 模块学习 logging(2)
- python的logging模块2
- Python 模块学习 logging(2)
- Python——模块(2)
- 2 python-模块和类
- Python(2) Python 模块帮助文档查询
- python模块 ---logging模块
- python模块-re模块
- python模块 - functools模块
- python 模块 模块文件
- python模块 - pickle模块
- python模块 - copy模块
- java 学习之 关于@Override
- KBE CellApp 跟 Space 的关系
- Yii 2.0邮箱类的简单应用
- IntentFilter 的匹配规则
- 关于JVM与内存溢出
- python模块2
- jmockit jacoco冲突
- cento7配置vsftpd遇到550错误的解决办法
- 【多线程-Sleep()和Interrup()方法】
- C#中base的用法
- HashMap实现原理分析
- HTTP连接管理的那些事儿
- CSS小姿势
- 居中滚动的Recyclerview