Reputation: 869
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?
Upvotes: 0
Views: 127
Reputation: 90007
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.
Upvotes: 1