Chapter 2. Sharing your Code: Modules of functions

image with no caption

Reusable code is great, but a shareable module is better. By sharing your code as a Python module, you open up your code to the entire Python community...and it’s always good to share, isn’t it? In this chapter, you’ll learn how to create, install, and distribute your own shareable modules. You’ll then load your module onto Python’s software sharing site on the Web, so that everyone can benefit from your work. Along the way, you’ll pick up a few new tricks relating to Python’s functions, too.

It’s too good not to share

You’ve been showing your function to other programmers, and they like what they see.

image with no caption

Yes, a function this good should be shared with the world.

Python provides a set of technologies that make this easy for you, which includes modules and the distribution utilities:

  • Modules let you organize your code for optimal sharing.

  • The distribution utilities let you share your modules with the world.

Let’s turn your function into a module, then use the distribution utilities to share your module with the wider Python programming community.

Turn your function into a module

A module is simply a text file that contains Python code. The main requirement is that the name of the file needs to end in .py: the Python extension. To turn your function ...

Get Head First Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.