I know how to add field to arcmap shapefile using Python:

import arcpy
arcpy.env.workspace = "H:\pythonexercise\NZL_rds\NZL_roads.shp"
arcpy.AddField_management("NZL_roads", "LENGTH", "TEXT","","","50")

But how to make the python code prompt a window for "field", "data type" and "length"? Also, what if I want add many fields at once like below:

  • field "SPEEDLIMIT" data type as "num" and length "3".
  • field "BREADTH" datatype as "num" and length "4"
  • field "LANE" datatype as "num" and length "4"

It should be dynamic, not fixed like my code.


Input can be asked this way:

var = raw_input("Enter something: ")
print "you entered ", var

For multiple input, you can ask:

var1, var2 = raw_input("Enter two field names separated by commas :").split(',')
  • Pure Python can do that but how does this "solution" work with the Python Toolbox that the asker appears to be writing? I think you and the asker should expand your posts to show a code snippet that works up to where the asker is stuck or where you claim to have the solution. – PolyGeo Jul 20 '16 at 6:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.