[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. DOM之概述

    body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...

  2. 免费180天的Ashampoo Anti-Virus 2014

    官方网站:https://www.ashampoo.com/cn/rmb/pde/0449/Security_Software/Ashampoo-Anti-Virus 活动页面:http://www. ...

  3. 5.3 将users表添加到xadmin后台

    在users模块中添加adminx.py文件,是xadmin后台管理默认的文件名,内容是: from .models import EmailVerifyRecord, Banner import x ...

  4. SQL优化:使用explain

    前文说了EXPLAIN的输出的含义,本文实战一下. Database Schema DROP DATABASE dbTest; CREATE DATABASE dbTest; USE dbTest; ...

  5. 一台 linux 主机装两个mysql

    启动 3306 nohup /usr/local/mysql5.1.7/bin/mysqld_safe & 启动 3307/usr/local/mysql/bin/mysqld --defau ...

  6. threading模块创建线程

    什么是线程 (thread) 线程也是一种多任务编程方式,可以使用计算机的多核资源.线程被称为轻量级的进程. 线程特征 *线程计算机多核分配的最小单位 *一个进程可以包含多个线程 *线程也是一个运行的 ...

  7. 20145237 Exp2 后门原理与实践

    20145237<网络对抗>Exp2 后门原理与实践 Windows获得Linux Shell 在Windows下,先使用ipconfig指令查看本机IP: 输入ncat.exe -l - ...

  8. 【转载】python安装numpy和pandas

    转载:原文地址 http://www.cnblogs.com/lxmhhy/p/6029465.html 最近要对一系列数据做同比比较,需要用到numpy和pandas来计算,不过使用python安装 ...

  9. python 命令行参数获取

    import argparse parser = argparse.ArgumentParser(description='Real-Time Filtering evaluation script ...

  10. charles手机抓包配置-1

    1.下载和安装Charles 下载和安装Charles软件.安装前要先安装Java运行环境,因为Charles是Java写的. 自己百度云上有破解版 2.安装电脑的Charles证书,对证书进行信任设 ...