Kinyanjui Wangonya

“Be curious. Read widely. Try new things. I think a lot of what people call intelligence boils down to curiosity.” - Aaron Swartz

github twitter linkedin medium email
Difference between a python module and a package
Feb 20, 2019
One minute read


Modules are single Python files that can be imported. Any python file can be a module. For example, if I have two Python files: and in the same directory:


def hello(name):
    print("Hello {}".format(name))

I can import that module in my

import module

module.hello("World!") # Hello World!

The same can be done in the interpreter:

>>> from module import hello
>>> hello("World!") # Hello World!


Packages are made up of multiple Python files (or modules), and can even include libraries written in different languages like C or C++. Seeing an __init.py__ file in a folder typically tells you that that folder is a Python package. The doesn’t have to contain any code – sometimes it does – it just has to be there for Python take that particular folder as a package.

📁 my_package
# __init.py__

from my_package.module import hello

When you import my_package in your script, the script will be run, giving you access to all of the functions in the package. In this case, it only gives access to the module.hello function.

Tags: python

Back to posts