GEOG 485:
GIS Programming and Software Development

Lesson 1 Practice Exercise 3 Solution

PrintPrint

Solution:

import arcpy

name = arcpy.GetParameterAsText(0)
print ("Hi, " + name)

Explanation:

There are other means of obtaining user input from the  PyScripter IDE, but this course is focused on executing scripts from within ArcGIS, so the exercise asked you to use arcpy's GetParameterAsText function. That means that, unlike the first two exercises, this script requires importing arcpy. As mentioned, the script can be executed from within PyScripter by entering the name parameter as a command line option. GetParameterAsText is zero-based, so the script is set up to get parameter 0 (the first and only parameter).

Note that it would also be acceptable to do away with the name variable as follows:

print ("Hi, " + arcpy.GetParameterAsText(0))