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

File paths in Python


It would be good to review how file paths are used in Python compared to how they are represented in Windows. In Python, file paths are strings, and strings in Python have special characters used to represent tabs (\t), newlines (\n), or carriage returns (\r), among many others. These special characters all incorporate single backslashes, making it very hard to create a file path that uses single backslashes. This would not be a big deal, except that file paths in Windows Explorer all use single backslashes.

There are a number of methods used to avoid this issue. Python was developed within the Linux environment, where file paths have forward slashes. This more Pythonic representation is also available when using Python in a Windows environment, demonstrated as follows:

Windows Explorer: "C:\Projects\PacktDB.gdb\Chapter3Results\Intersect71Census"
Pythonic version:  "C:/Projects/PacktDB.gdb/Chapter3Results/Intersect71Census"

Within a Python script, the file path with the...