advanced points from open source python projects
来源:互联网 发布:linux修改dns地址 编辑:程序博客网 时间:2024/06/07 05:07
mainly for open source mongoengine
(1)fallback import
(2)import from the future
(3)customize imports by _ _ all _ _
the situation: sometimes, it does not make much sense that exporting utility functions and classes to external code. in order to control what objects get exposed when you import a module like this, you can specify _ _ all _ _ somewhere in this module.
All that you need to do is supply a list—or some other sequence—that contains the names of objects that should get imported when the module is imported using an asterisk(*)
#module a__all__ = ['func1']def func1(): returndef func2(): return 0#module bfrom a import *func1() #OKfunc2() #NOK
(4)absolute/relative(intra-package) import
about imports in Python PEP328(multiple-lines,absolute/relative) and PEP338(executing modules as scripts) and PEP366(main modules explicit relative imports)
(a)absolute import
For example, the statement import pkg_or_module_name
may be ambiguous.
To resolve ambiguity, it is proposed that pkg_or_module_name will always be a module or package reachable from sys.path, which is called an absolute import.
(b)relative import
Note: it is some difficulty to directly execute a module with relative import as a top-level script
(5)script&module
a python files may be loaded in two styles, either as a top-level script or as a module.
- advanced points from open source python projects
- iPhone/Mac Open Source Projects(From projectswithlove.com)
- Open Source .NET projects
- Open Source BI Projects
- Open source projects
- .NET open source projects
- wxwidgets open source projects
- Android Open Source Projects
- Android Open Source Projects
- Open Source Projects
- Baidu open source projects
- Open Source BI Projects
- Web2.0 Open Source Projects
- Open Source Projects about Multimedia
- .NET Open Source Developer Projects
- .NET Open Source Developer Projects
- open source workflow & CMS & issue tracking projects
- comments on open source groupware projects
- selenium+java自动化测试环境搭建介绍
- java网络ios七层,五层模型数据流图
- 隐藏实现
- javaEE案例下载-名片(回收站)管理系统源码免费下载
- String类的使用与理解
- advanced points from open source python projects
- 读《在建筑中发现梦想》
- 关于System类的深入理解
- codevs 1173 最优贸易
- 利用回调函数实现通用冒泡排序
- New Year and Old Property CodeForces
- HTML基础
- class Date 日期类
- 为了续租MP