Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Modular Programming with Python

You're reading from   Modular Programming with Python Introducing modular techniques for building sophisticated programs using Python

Arrow left icon
Product type Paperback
Published in May 2016
Publisher Packt
ISBN-13 9781785884481
Length 246 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Erik Westra Erik Westra
Author Profile Icon Erik Westra
Erik Westra
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Introducing Modular Programming 2. Writing Your First Modular Program FREE CHAPTER 3. Using Modules and Packages 4. Using Modules for Real-World Programming 5. Working with Module Patterns 6. Creating Reusable Modules 7. Advanced Module Techniques 8. Testing and Deploying Modules 9. Modular Programming as a Foundation for Good Programming Technique Index

The Python Standard Library

One of the buzzwords used to describe Python is that it is a batteries included language, that is, it comes with a rich collection of built-in modules and packages called the Python Standard Library. If you've written any non-trivial Python program, you've almost certainly used modules from the Python Standard Library to do so. To get an idea of how vast the Python Standard Library is, here are a few example modules from this library:

Module

Description

datetime

Defines classes to store and perform calculations using date and time values

tempfile

Defines a range of functions to work with temporary files and directories

csv

Supports reading and writing of CSV format files

hashlib

Implements cryptographically secure hashes

logging

Allows you to write log messages and manage log files

threading

Supports multi-threaded programming

html

A collection of modules (that is, a package) used to parse and generate HTML documents

unittest

A framework for creating and running unit tests

urllib

A collection of modules to read data from URLs

These are just a few of the over 300 modules available in the Python Standard Library. As you can see, there is a vast range of functionality provided, and all of this is built in to every Python distribution.

Because of the huge range of functionality provided, the Python Standard Library is an excellent example of modular programming. For example, the math standard library module provides a range of mathematical functions that make it easier to work with integer and floating-point numbers. If you look through the documentation for this module (http://docs.python.org/3/library/math.html), you will find a large collection of functions and constants, all defined within the math module, that perform almost any mathematical operation you could imagine. In this example, the various functions and constants are all defined within a single module, making it easy to refer to them when you need to.

In contrast, the xmlrpc package allows you to make and respond to remote procedure calls that use the XML protocol to send and receive data. The xmlrpc package is made up of two modules: xmlrpc.server and xmlrpc.client, where the server module allows you to create an XML-RPC server, and the client module includes code to access and use an XML-RPC server. This is an example of where a hierarchy of modules is used to logically group related functionality together (in this case, within the xmlrpc package), while using sub-modules to separate out the particular parts of the package.

If you haven't already done so, it is worth spending some time to review the documentation for the Python Standard Library. This can be found at https://docs.python.org/3/library/. It is worth studying this documentation to see how Python has organized such a vast collection of features into modules and packages.

The Python Standard Library is not perfect, but it has been improved over time, and the library as it is today makes a great example of modular programming techniques applied to a comprehensive library, covering a wide range of features and functions.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime