HOW TO

Write the results of geoprocessing tools to a text file using Python

Last Published: July 12, 2022

Summary

Instructions provided describe how to write the results of geoprocessing tools to a text file.

When a geoprocessing tool is run, the results are written to the Geoprocessing Results Window in ArcMap or ArcCatalog; they are also written to a history log file. There are times when it is helpful to have the geoprocessing results written to a text file.

Procedure

The following Python script sample runs the Buffer tool and then writes the geoprocessing results to a text file. The script can be run through the Python window in ArcMap. Refer to ArcMap: Using the Python window for more information.

Code Sample for ArcGIS 10.x:

import arcpy

# Input feature classes to buffer
inFC = "C:\\Temp\\Georgia.shp"

# Output Feature Class
outFC = "C:\\Temp\\Georgia_Buffer.shp"

# Buffer distance
dist = "50 miles"

# Run buffer tool
arcpy.Buffer_analysis(inFC, outFC, dist)

# Write messages to a Text File
txtFile = open("c:\\temp\\GPMessages.txt","w")
txtFile.write (arcpy.GetMessages())
txtFile.close()

Code Sample for ArcGIS 9.2/9.3.x:

import arcgisscripting
gp = arcgisscripting.create()
gp.Toolbox = "Analysis"

# Input feature classes to buffer
inFC = "C:\\Temp\\Georgia.shp"

# Output Feature Class
outFC = "C:\\Temp\\Georgia_Buffer.shp"

# Buffer distance
dist = "50 miles"

# Run buffer tool
gp.buffer(inFC, outFC, dist)

# Write messages to a Text File
txtFile = open("c:\\temp\\GPMessages.txt","w")

txtFile.write (gp.GetMessages())

txtFile.close()

Article ID:000011114

Software:
  • ArcMap 9 x
  • ArcMap 10 8
  • ArcMap 10 x
  • ArcMap 10 7
  • ArcMap 10 6

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic