Book Image

ArcPy and ArcGIS: Geospatial Analysis with Python

Book Image

ArcPy and ArcGIS: Geospatial Analysis with Python

Overview of this book

Table of Contents (19 chapters)
ArcPy and ArcGIS – Geospatial Analysis with Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a Python module


An important step towards creating reusable code is to package its component functions into a module that can be called from the Python path by any script. To start, we need to create a folder in the site-packages folder where Python modules are placed when downloaded and extracted using the Python module process, or when running the setup.py script included with shared modules.

Modules package together functions in one or more scripts into a folder that can be shared with others (though they often depend on other modules to run). We have used some of the built-in modules such as the csv module and third-party modules such as ArcPy. Let's explore their construction to get a feel of how a module is packaged for use and sharing.

Note

Many modules are not placed within the site-packages folder, but they require the Python path to be modified to make them importable. Placing modules within the site-packages folder eliminates this requirement.

Open up the site-packages folder...