Python 中 __all__ 的作用
来源:互联网 发布:美国 博士 知乎 编辑:程序博客网 时间:2024/05/17 14:16
1.测试文件foo.py
1
2
3
4
5
6
7
8
9
10
# -*- coding: utf-8 -*-
# import sys
# reload(sys)
# sys.setdefaultencoding('gbk')
__all__
=
[
'bar'
,
'baz'
]
waz
=
5
bar
=
10
def
baz():
return
'baz'
2.引入上文件,创建run-foo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
# -*- coding: utf-8 -*-
# import sys
# reload(sys)
# sys.setdefaultencoding('gbk')
from
foo
import
*
print
bar
print
baz
# The following will trigger an exception, as "waz" is not exported by the module
# 下面的代码就会抛出异常,因为 "waz"并没有从模块中导出,因为 __all__ 没有定义
print
waz
3.运行结果
4.把foo.py的“__all__ = ['bar', 'baz']” 注释,运行正常
它不仅在第一时间展现了模块的内容大纲,而且也更清晰的提供了外部访问接口。
阅读全文
0 0
- Python 中 __all__ 的作用
- python的moudles文件中__all__作用
- python的moudles文件中__all__作用
- [问与答]Python 中 __all__ 的作用 ?
- __all__=[]的作用
- python中模块的__all__属性
- python __all__的用法
- python关于__all__的定义
- 【python】__all__
- Python __all__
- python __all__
- Python – __all__ function
- 20 Python __all__
- python中的__all__和__slots__
- python中的__all__与__import__
- 【Python】用 __all__ 暴露接口
- python中的__all__和__slots__
- python里__all__ 属性用法
- C++ Primer Plus 编程练习 第三章
- C++ 复习要点
- javascript第六章2
- "ZUMA"(COCI#2009-2010#contest 5)
- link标签的用法及link属性大全
- Python 中 __all__ 的作用
- 安装Webtatic yum源
- 抽奖
- java.net.ProtocolException: Server redirected too many times (20)
- Linux笔记(1):VMware虚拟机 Ubuntu 16.04 安装 VMware Tools
- Android的Gson的使用方法,实现Json结构间相互转换
- PHP 汉字转拼音
- AngularJS查询
- 深入理解RunLoop