Book Image

Python Fundamentals

By : Ryan Marvin, Mark Ng’ang’a, Amos Omondi
Book Image

Python Fundamentals

By: Ryan Marvin, Mark Ng’ang’a, Amos Omondi

Overview of this book

<p>After a brief history of Python and key differences between Python 2 and Python 3, you'll understand how Python has been used in applications such as YouTube and Google App Engine. As you work with the language, you'll learn about control statements, delve into controlling program flow and gradually work on more structured programs via functions.</p> <p>As you settle into the Python ecosystem, you'll learn about data structures and study ways to correctly store and represent information. By working through specific examples, you'll learn how Python implements object-oriented programming (OOP) concepts of abstraction, encapsulation of data, inheritance, and polymorphism. You'll be given an overview of how imports, modules, and packages work in Python, how you can handle errors to prevent apps from crashing, as well as file manipulation.</p> <p>By the end of this book, you'll have built up an impressive portfolio of projects and armed yourself with the skills you need to tackle Python projects in the real world.</p>
Table of Contents (12 chapters)
Python Fundamentals
Preface

Modules and Packages


In this section, we will turn our focus toward the standard Python modules and Python packages.

The Module Search Path

When you import any module, Python will first check whether there is a built-in module with the specified name. An example of a built-in module is the string module.

If no built-in module is found, the interpreter will look for a file with the name of the module and the .py extension in the directories given by the sys.path variable. This variable is simply a list of strings which specifies where to search for modules.

How this variable is built is beyond the scope of this book. However, it is partly dependent on your defined PYTHONPATH and can be modified if necessary. You can read more about it in the Python documentation at https://docs.python.org/3/library/sys.html#sys.path.

For your interest, though, you can inspect the sys.path in your current environment by running the following commands on your terminal:

>>> import sys
>>> sys.path...