python包本身就是一个模块吗?

时间:2014-02-01 16:47:45

标签: python module package python-internals

我只是试图理解python中的模块和包,并且像我所理解的那样:

A module is a file containing Python definitions and statements.

A package is a directory containing modules or other packages.

现在,我创建了一个非常简单的目录结构,如下所示:

my_package/
      __init__.py
      my_module.py

然后,在翻译中,我做了:

>>> import my_package
>>> type(my_package)
<type 'module'>

>>> from my_package import my_module
>>> type(my_module)
<type 'module'>

所以,Python说,my_package和my_module都是模块。包裹在哪里?包只是用于描述目的的术语,并且在核心语言中没有作为类或对象的官方标识吗?解释器的包和模块是什么?

1 个答案:

答案 0 :(得分:1)

是的,包可以作为模块导入;模块的内容位于__init.py__

术语包指的是目录;它允许模块和子包存在于包命名空间中。