concept script in category geoprocessing

appears as: scripts, script, scripts
Geoprocessing with Python

This is an excerpt from Manning's book Geoprocessing with Python.

In addition, Python is multiplatform, so unless you’ve used an extra module that’s specific to one operating system, a Python script that you write on one machine will run on any other machine, provided the required modules are installed. You can use your Linux box to develop a set of scripts and then give them to a colleague who uses Windows, and everything should work fine. You do need to install a Python interpreter to run the code, but those are freely available for major desktop operating systems.

Another reason for using Python is that it’s an interpreted language, so programs written in Python will run on any computer with an interpreter, and interpreters exist for any operating system you’re likely to use. To run a Python script, you need the script and an interpreter, which is different from running an .exe file, for example, where you only need one file. But if you have an .exe file, you can only run it under the Windows operating system, which is a bummer if you want to run it on a Mac or Linux. However, if you have a Python script, you can run it anywhere that has an interpreter, so you’re no longer limited to a single operating system.

2.2. Basic structure of a script

Some of the first things you’ll see right at the top of most Python scripts are import statements. These lines of code load additional modules so that the scripts can use them. A module is basically a library of code that you can access and use from your scripts, and the large ecosystem of specialized modules is another advantage to using Python. You’d have a difficult time working with GIS data in Python without extra modules that are designed for this, similar to the way tools such as GIMP and Photoshop make it easier to work with digital images. The whole point of this book is to teach you how to use these tools for working with GIS data. Along the way, you’ll also use several of the modules that come with Python because they’re indispensable for tasks such as working with the file system.