python有趣的属性
__all__可用于模块导入时限制,如:
from
module import *
此时被导入模块若定义了__all__属性,则只有all内指定的属性、方法、类可被导入;
若没定义,则模块内的所有将被导入。

例子:比如python中的unittest模块

__all__ = ['TestResult', 'TestCase', 'TestSuite',
'TextTestRunner', 'TestLoader', 'FunctionTestCase', 'main',
'defaultTestLoader', 'SkipTest', 'skip', 'skipIf', 'skipUnless',
'expectedFailure', 'TextTestResult', 'installHandler',
'registerResult', 'removeResult', 'removeHandler']

# Expose obsolete functions for backwards compatibility
__all__.extend(['getTestCaseNames', 'makeSuite', 'findTestCases'])

print unittest.__all__

结果:['TestResult', 'TestCase', 'TestSuite', 'TextTestRunner', 'TestLoader', 'FunctionTestCase', 'main', 'defaultTestLoader', 'SkipTest', 'skip', 'skipIf', 'skipUnless', 'expectedFailure', 'TextTestResult', 'installHandler', 'registerResult', 'removeResult', 'removeHandler',
   'getTestCaseNames', 'makeSuite', 'findTestCases']
如果某个.py import了unittest后,这个模块中的类、成员、方法、属性将被引入。
其中__all__.extend为在原来__all__的基础上增加的新的方法。

最新文章

  1. Xamarin Studio在Mac环境下的配置和Xamarin.iOS常用控件的示例
  2. Base64编码格式详解
  3. Travis-CI与Latex构建开源中文PDF
  4. UIView背景渐变三种方法
  5. 修改 apache http server 默认站点目录
  6. wireshark的ubuntu更新ppa源
  7. An error has occurred,See error log for more details
  8. SQL点滴26—常见T-SQL面试解析
  9. [转]Creating an iPhone Daemon
  10. java byte【】数组与文件读写
  11. GoodReads: Machine Learning (Part 3)
  12. 基于docker+reveal.js搭建一个属于自己的在线ppt网站
  13. google软件测试之道读后感(二)
  14. 【BZOJ4805】欧拉函数求和(杜教筛)
  15. 通过游戏来学习CSS的Flex布局
  16. Unity3d自制字体
  17. GUI之ScrollView的使用
  18. Latex: IEEEtrans模板下 扩大标题宽度
  19. PHP开发安全问题总结
  20. day3之文件操作

热门文章

  1. rabbitmq与erlang版本
  2. 服务器同一个tomcat部署2两个相同的项目
  3. Python函数递归调用
  4. 用python和GDAL 读取GRIB数据
  5. vue学习笔记(一)---- vue指令( v-bind 属性绑定 )
  6. Filebeat 根据不同的日志设置不同的索引
  7. Spark为什么只有在调用action时才会触发任务执行呢(附算子优化和使用示例)?
  8. MATLAB中的参数估计函数详解及调用示例【联合整理】
  9. kong in kubernetes
  10. Azure Data Factory(二)复制数据