简体   繁体   中英

Is python package itself a module?

I was just trying to understand modules and packages in python, and as fas as I understood:

A module is a file containing Python definitions and statements.

A package is a directory containing modules or other packages.

Now, I made a very simple directory structure like below:

my_package/
      __init__.py
      my_module.py

Then, inside the interpreter, I did:

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

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

So, Python says, my_package and my_module, both are modules. Where is the package? Is package just a term used for description purposes and has no official identity as a class or object inside the core language? What are packages and modules for the interpreter?

Yes, a package can be imported as a module; the module's contents are in __init.py__ .

The term package refers to the directory; it allows modules and subpackages to exist in the package namespace.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM