Book Image

Modular Programming with Python

By : Erik Westra
Book Image

Modular Programming with Python

By: Erik Westra

Overview of this book

Python has evolved over the years and has become the primary choice of developers in various fields. The purpose of this book is to help readers develop readable, reliable, and maintainable programs in Python. Starting with an introduction to the concept of modules and packages, this book shows how you can use these building blocks to organize a complex program into logical parts and make sure those parts are working correctly together. Using clearly written, real-world examples, this book demonstrates how you can use modular techniques to build better programs. A number of common modular programming patterns are covered, including divide-and-conquer, abstraction, encapsulation, wrappers and extensibility. You will also learn how to test your modules and packages, how to prepare your code for sharing with other people, and how to publish your modules and packages on GitHub and the Python Package Index so that other people can use them. Finally, you will learn how to use modular design techniques to be a more effective programmer.
Table of Contents (16 chapters)
Modular Programming with Python
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Wrappers


A wrapper is essentially a group of functions that call other functions to do the work:

Wrappers are used to simplify an interface, to make a confusing or badly designed API easier to use, to convert data formats into something more convenient, and to implement cross-language compatibility. Wrappers are also sometimes used to add testing and error-checking code to an existing API.

Let's take a look at a real-world application of a wrapper module. Imagine that you work for a large bank and have been asked to write a program to analyze fund transfers to help identify possible fraud. Your program receives information, in real time, about every inter-bank funds transfer that takes place. For each transfer, you are given:

  • The amount of the transfer

  • The ID of the branch in which the transfer took place

  • The identification code for the bank the funds are being sent to

Your task is to analyze the transfers over time to identify unusual patterns of activity. To do this, you need to calculate, for...