[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的更多相关文章

  1. 解决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 ...

  2. Python Modules and Packages – An Introduction

    This article explores Python modules and Python packages, two mechanisms that facilitate modular pro ...

  3. Installing Python Modules

    Email: distutils-sig@python.org As a popular open source development project, Python has an active s ...

  4. python modules and packages

    https://realpython.com/python-modules-packages/ 在软件开发中,一个module是具有一些相关功能的软件集合,比如,当你在开发一个游戏时,可能会有一个模块 ...

  5. [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 ...

  6. [Python Modules] unittest.mock

    五夜光寒,照来积雪平于栈.西风何限,自起披衣看. 对此茫茫,不觉成长叹.何时旦,晓星欲散,飞起平沙雁. 在某个Python程序中看到这么一行 from unittest import mock 看起来 ...

  7. 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要原本你的系统原 ...

  8. 升级 python 2.6.6 系统到 2.7.10 版本

    CentOS 6 系统默认 Python 版本是:2.6.6 平时在使用中遇到很多的库要求是 2.7.x 版本的库,比如使用 ConfigParser 库,在 2.6 版本库就不支持没有 value ...

  9. K-Means clusternig example with Python and Scikit-learn(推荐)

    https://www.pythonprogramming.net/flat-clustering-machine-learning-python-scikit-learn/ Unsupervised ...

随机推荐

  1. Mysql04

    mysql: dbs 数据库系统 bdms 数据库管理系统 bda 数据库管理员 db 数据库 dba通过dbms来操作db! 关系型数据库和非关系型数据库 登录mysql mysql -h主机地址 ...

  2. Python基础学习----拆包

    拆包,多用在多值参数种. 1.多值参数. 有时候,在函数的参数转递时,不单只传输单个字符的参数,比如有元组和字典的参数,这时候我们就使用多值参数. *args 代表元组的多值参数 *kwargs 代表 ...

  3. OPENCV Linux安装

    https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html

  4. vue music-抓取歌单列表数据(渲染轮播图)

    下载安装新依赖 babel-runtime:对es6语法进行转译 fastclick:对移动端进行点击300毫秒延迟 ,,取消掉 babel-polyfill:API 先添加,在npm install ...

  5. Qt flash_eraseall nandwrite 进度条显示擦除、烧录

    /***************************************************************************** * Qt flash_eraseall n ...

  6. CI框架------codeIgniter

    之前学习了thinkphp,学完之后印象不太深刻,在网上询问了一下,他们都说多学几个框架,以后可以自己写框架. 于是自己就放下thinkphp,下定决心再学一个,于是又从网上看了几个框架,综合比较了一 ...

  7. 【java多线程】java的线程池分析

    (一)线程池的拒绝策略 --->拒绝策略的接口java.util.concurrent.RejectedExecutionHandler --->终止策略(默认):java.util.co ...

  8. web程序1

  9. SD卡驱动学习

    https://blog.csdn.net/zqixiao_09/article/category/6163492 sd 协议解析: https://blog.csdn.net/g_salamande ...

  10. IAR 9+ 编译 TI CC2541 出现 Segment ISTACK (size: 0xc0 align: 0) is too long for segment definition.

    IAR 9+ 编译 TI CC2541 出现 Segment ISTACK (size: 0xc0 align: 0) is too long for segment definition. Segm ...