Skip to Content
Python Distilled
book

Python Distilled

by David M. Beazley
September 2021
Beginner to intermediate
352 pages
11h 27m
English
Addison-Wesley Professional
Content preview from Python Distilled

8. Modules and Packages

Python programs are organized into modules and packages that are loaded with the import statement. This chapter describes the module and package system in more detail. The primary focus is on programming with modules and packages, not the process of bundling code for deployment to others. For the latter, consult the latest documentation at https://packaging.python.org/tutorials/packaging-projects/.

8.1 Modules and the import Statement

Any Python source file can be imported as a module. For example:

# module.py

a = 37

def func():
    print(f'func says that a is {a}')

class SomeClass:
    def method(self):
        print('method says hi')

print('loaded module')

This file contains common programming elements—including ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Testing with pytest

Python Testing with pytest

Brian Okken
Robust Python

Robust Python

Patrick Viafore

Publisher Resources

ISBN: 9780134173399