Python Modules
[Python Modules]
1. a module is a python source file.
2. a package is a directory with a __init__.py file within it.
1) 如果目录下没有__init__.py文件, 则python不会认为这个目录是个package, 这意味着 import package 以及 from package import * 以及 from package import xxx 都会失败.
2) 无论是import package还是from package import *都会执行__init__.py, 不同的是, 当执行from package import *时, python会自动import __all__中的文件.
3)__all__对于单一的Module同样有效。
3. import哪个符号, 那么该符号就会加入当前作用域中.
4. from module import *,不会导入以 "_"(单下划线开头的名字),“__”(双下划线)的name mangling只在Class的命名空间中才有

虽然import *不会导入"_"前缀的名字,但是import module的话仍旧可以访问到,所以在一个module中,不能以“_”的手段来定义私有变量
参考:
1、http://www.blogjava.net/cpegtop/articles/383806.html
【Importing * From a Package】
If __all__ is not defined, the statement from sound.effects import * does not import all submodules from the package sound.effects into the current namespace; it only ensures that the package sound.effects has been imported (possibly running any initialization code in __init__.py) and then imports whatever names are defined in the package. This includes any names defined (and submodules explicitly loaded) by __init__.py.
from xxx import * 不会导入xxx包下的所有submodule,除非该submodule在__init__.py中会被引用到。
【Intra-package References】

Python Modules的更多相关文章
- 解决yum升级的问题“There was a problem importing one of the Python modules”
yum命令升级的时候,报出这个错误. There was a problem importing one of the Python modules required to run yum. The ...
- Python Modules and Packages – An Introduction
This article explores Python modules and Python packages, two mechanisms that facilitate modular pro ...
- Installing Python Modules
Email: distutils-sig@python.org As a popular open source development project, Python has an active s ...
- python modules and packages
https://realpython.com/python-modules-packages/ 在软件开发中,一个module是具有一些相关功能的软件集合,比如,当你在开发一个游戏时,可能会有一个模块 ...
- [Python] Reuse Code in Multiple Projects with Python Modules
A module is a function extracted to a file. This allows you to import the function and use it in any ...
- [Python Modules] unittest.mock
五夜光寒,照来积雪平于栈.西风何限,自起披衣看. 对此茫茫,不觉成长叹.何时旦,晓星欲散,飞起平沙雁. 在某个Python程序中看到这么一行 from unittest import mock 看起来 ...
- centos系统重装python或yum 报There was a problem importing one of the Python modules required to run yum. The error leading to this problem was:错误
sudo vim /usr/bin/yum #修个python所在的路径,例如 #/usr/local/bin/python2.6 或 /usr/local/bin/python2.7要原本你的系统原 ...
- 升级 python 2.6.6 系统到 2.7.10 版本
CentOS 6 系统默认 Python 版本是:2.6.6 平时在使用中遇到很多的库要求是 2.7.x 版本的库,比如使用 ConfigParser 库,在 2.6 版本库就不支持没有 value ...
- K-Means clusternig example with Python and Scikit-learn(推荐)
https://www.pythonprogramming.net/flat-clustering-machine-learning-python-scikit-learn/ Unsupervised ...
随机推荐
- PHPCMS v9 二次开发_验证码结合Session开发
本文主要讲解了在V9中使用v9自带验证码并且需要使用session的情况下,多种问题的解决.:).如有问题或者更好的解决办法,希望不吝赐教. 1.前端调用验证码 pc_base::load_sys_c ...
- 关于apply、call和bind的总结
基础知识不是你看了一遍书或者两篇文章就能掌握的. 之前看书看文章时,感觉自己看懂了就掌握了.呵呵!too young!too naive! 以前的坑还是要一铲一铲的填上的. 高程上面关于apply和c ...
- L194
For many of us, asking for help is it difficult concept. We may feel as if we are admitting a weakne ...
- Python 高性能并行计算之 mpi4py
MPI 和 MPI4PY 的搭建上一篇文章已经介绍,这里面介绍一些基本用法. mpi4py 的 helloworld from mpi4py import MPI print(&quo ...
- Linux 中同名进程的查杀
长久一段时间没有做任何工作总结了,如果用工作忙来敷衍那是欺骗自己,承认这一段时间拒绝进步了. 在系统运维中,有许多同名进程需要kill是常有的事情, 数一下battle这个进程的数量 [root@HD ...
- spring注解-@Autowired。@Resource。@Service
Spring的@Autowired注解.@Resource注解和@Service注解 什么是注解 传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点: ...
- 新手,Visual Studio 2013 配置Boost库,如何编译和选择
QuantLib installation in VC++ 2010 and later 参考:http://quantlib.org/install/vc10.shtml 1,到官网下载最新的boo ...
- HDU5296 Annoying problem(LCA)
//#pragma comment(linker, "/STACK:1677721600") #include <map> #include <set> # ...
- python list添加元素的几种方法
1. 加单个, append 2. 加个list, expend 3, 最简单的, 两个list可以用"+" (加号)
- docker 数据卷 ---- 进阶篇
笔者在<Docker 基础 : 数据管理>一文中介绍了 docker 数据卷(volume) 的基本用法.随着使用的深入,笔者对 docker 数据卷的理解与认识也在不断的增强.本文将在前 ...