Cover by Paul Barry

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required