Using Python: Part 4: Using External Modules

Learning Python

Using Python

Python is a general-purpose interpreted programming language. It emphasizes readability through the use of whitespace and supports multiple programming paradigms such as functional and object-oriented models.


Using External Modules

Python has a robust community that contributes to external modules. In the past, these had to be downloaded and often even individually compiled for different operating systems. To help streamline this process, the tool pip now exists.

Installing Pip

For Linux-based and MacOS X systems, pip can be installed (if it is not already) through following the instructions on the Installation page.

For Windows systems, it is highly recommended to download a version of Python 3 or greater that comes with pip built into it.

Using Pip

As a command-line tool, pip is used through typing commands.

To install a package using pip, it looks like the following:

pip install packageName

Once a package is installed, it is available to be used in a Python file.

Working with Modules

To include an external module in a Python project the keywords from and import are used.

from

Some modules contain many files or multiple possible modules to use. The from keyword helps in selecting from what project to include files.

import

The import keyword includes the specified modules. When used on a collection of files, it will include all of them. When paired with from in the pattern of fromimport… only the specified modules will be included.

Play with the example on Repl.it!