Environments in script tools are like environments in any other tool—environment values are passed down to the script tool, where they are automatically applied to any tools run within the script. You can also set environments within a script tool, thereby overriding any passed-down environments. Environment values set within scripts only apply to the execution of the script; passed-down environment values are not altered. In the following sample script, the current workspace value is overridden in the script.
import arcpy
from arcpy import env
# Print the passed-down current workspace environment setting
#
arcpy.AddMessage("The passed-down current workspace is: %s" % env.workspace)
# Set a new workspace, overriding the passed-down workspace
#
env.workspace = "e:/data/script.gdb"
arcpy.AddMessage("The new current workspace is: %s" % env.workspace)
The following ArcPy functions allow you to manipulate environment settings:
Stand-alone or called scripts
There are two situations where the script does not receive passed-down environment settings. The first is when the script is run outside an ArcGIS application, such as from the operating system command prompt. The second is when a script calls another script: there is no way for the calling script to know that the called script will call geoprocessing functionality. In such situations, you can use the LoadSettings function, which can read environment settings from an XML file.