Python suggest change

Difference between a module and a package


A module is a single Python file that can be imported. Using a module looks like this:

def hi():
    print("Hello world!")

import module

in an interpreter

>>> from module import hi
>>> hi()
# Hello world!


A package is made up of multiple Python files (or modules), and can even include libraries written in C or C++. Instead of being a single file, it is an entire folder structure which might look like this:

Folder package

from import woof
from package.hi import hi

def woof():

def hi():
    print("Hello world!")

All Python packages must contain an file. When you import a package in your script (import package), the script will be run, giving you access to the all of the functions in the package. In this case, it allows you to use the package.hi and package.woof functions.

Putting package in .zip

It is possible to put a Python package in a ZIP file, and use it that way if you add these lines to the beginning of your script:

import sys

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents
32 Set
46 Enum
95 Difference between a module and a package
105 Stack
119 Mixins
121 ArcPy
127 Arrays
139 Neo4j
141 Curses
146 heapq
155 Audio
156 pyglet
158 ijson
161 Flask
164 pygame
167 Gzip
168 ctypes
187 shelve
  ↑ ↓ to navigate     ↵ to select     Esc to close