Which is Preferred: sys.argv or arcpy.GetParameterAsText in Accessing Geoprocessing Tool Parameters


One of my clients asked me to run the script geoprocessing tool, I developed for him, from Command Prompt. The tool has nine parameters and it is contained in a custom ArcGIS Toolbox. It is intended to be run inside ArcMap. I finished developing the tool and running it perfectly as any other built-in tool.

At the beginning, I thought it needs little modifications to run it from command prompt. In particular, I thought I need to get the parameter values through sys.argv as I am used to do for Python scripts, intended to be run from command prompt. what was surprising, It doesn't need any modification to do that.

The function arcpy.GetParameterAsText works as if you would use sys.argv to access the parameters. According to ArcGIS Help Documentation, Arcpy.GetParameterAsText is preferred since it has no character limit, while sys.argv has limitations on the number of characters it can accept.

The illustration below shows a script tool dialog box with three parameters.

Script tool parameters
User Interface of the tool (source: ArcGIS Help)

Below is a part of Python script to access parameter values through the function arcpy.GetParameterAsText.

 (source: ArcGIS Help)

The same code but this time, sys.argv is used to read the values of parameters are illustrated below:
 (source: ArcGIS Help)
For more information, visit the ArcGIS Help through the following link:


No comments

Powered by Blogger.