Setting environments in the Python window

Each tool has a set of parameters it uses to execute an operation. Some of these parameters are common among all tools, such as a tolerance or output location. These parameters may obtain their default values from a geoprocessing environment that all tools utilize during their operation. When a tool is executed, the current environment settings can also be used as global input parameter values. Settings such as an area of interest, the spatial reference of the output dataset, and the cell size of a new raster dataset can all be specified with geoprocessing environments.

In ArcPy, geoprocessing environments are organized as properties under the ArcPy class env. In the example below, several environment values are printed to the display, then set to new values.

>>> print arcpy.env.overwriteOutput
True

>>> print arcpy.env.workspace
None

>>> arcpy.env.overwriteOutput = False
>>> arcpy.env.workspace = "c:/temp"
>>> print arcpy.env.overwriteOutput
False

>>> print arcpy.env.workspace
c:/temp

>>>

Keeping track of environments in the Python window

Since geoprocessing environments can significantly affect tool operation and output, it is important to be able to keep track of environment settings and to reset environments to their default states when necessary.

The ArcPy function ResetEnvironments can be used to restore the default environment values.

>>> arcpy.ResetEnvironments()
>>>

The ArcPy function ListEnvironments can be used to create a list of all geoprocessing environments. This list can be used to access and print all environments and their current values. This example only shows two environments, but all environments and their values are printed using this code.

>>> environments = arcpy.ListEnvironments()
... for environment in environments:
...     envSetting = eval("arcpy.env." + environment)
...     print "%-30s: %s" % (environment, envSetting)
...
newPrecision                  : SINGLE

autoCommit                    : 1000



12/15/2011