Python3包机制
来源:互联网 发布:模拟人生4捏脸美女数据 编辑:程序博客网 时间:2024/06/07 23:44
先给出包结构:
Class_1.py内容:
from main.sub_2.Class_2 import Class_2class Class_1: def show(self): print("this is class_1.show()") cls2 = Class_2(); cls2.show()Module_1.py内容:
from main.sub_2 import Module_2def show(): print("this is module_1.show()") Module_2.show()Class_2.py
class Class_2: def show(self): print("this is class_2.show()")Module_2.py内容:
def show(): print("this is module_2.show()")run.py内容:
from main.sub_1.Class_1 import Class_1from main.sub_1 import Module_1if(__name__ == "__main__"): cls1 = Class_1() cls1.show() Module_1.show()Python中的package必须包含一个__init__.py的文件,__init__.py可以为空,只要它存在,就表明此目录应被作为一个package处理。
需要注意的一点是类和普通的代码片段(函数和变量)模块的引入是有区别的:
1、如果是类,像from main.sub_2.Class_2 import Class_2这样引入
2、如果是代码片段(函数和变量),像from main.sub_2 import Module_2这样引入,也可以一次引入多个模块
from main.sub_2 import Module_2,Module_x前提是Module_2个Module_x是在同一个包下
0 0
- Python3包机制
- python3 socket抓包
- Python3包管理
- Python3 requests包学习
- python3 包管理工具问题
- 包机制
- Python3.2官方文档教程--包
- python3中builtwith包不能用怎么办
- Python3 安装bulitwith 和urllib2包
- Linux下源码包安装python3
- python3.5如何安装statsmodels包?
- python3 用ConfigParser包处理 ini文件
- python3安装beautifulsoup包的方法
- Python3 上传Python包到PyPi
- windows下python3扩展包的配置
- python3抓包百度图片并下载
- python3 闭包的两种情况
- python3处理http请求的包
- C++Windows下创建多级目录
- Fixed数据类型
- CPU性能评估标准
- HTTP请求中POST与GET的区别
- 操作系统学习笔记(2)——中断和异常
- Python3包机制
- eMMC是什么?
- android跳转界面(页面)发现界面首先出现的是下面的部分,滑动才能看到上面的解决方法
- qemu-2.4.0.1编译问题
- -rw-r--r-- 是什么意思?
- linux lsof详解
- exits和in的区别
- Java 集合概览
- Android 设置页面 及 背景音乐 的实现