2

This question already has an answer here:

I'm new learning as I go, I have read some of the Answers posted, and I've gotten this far, I was able to add a new field to a GBD, I wanted to have the Length be 50, but it created a field with 255, so I didn't get something quite right the code I used below the feature class is wax_ru the Field name is HN_AW Text is the Type of Field, and 50 is the Default Value I wanted, but as I stated it created the field with 255

import arcpy
from arcpy import env
env.workspace = "C:\Users\angelaw\OneDrive - TomTom\Resources\Australia\PSMA_MAY_2018\PSMA_Deltas_test\PSMA_MAY_deltas.gdb"

arcpy.AddField_management ("wax_ru", "HN_AW","TEXT",50)

marked as duplicate by Evil Genius, Vince, Andre Silva, xunilk, Midavalo Jun 16 '18 at 3:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

You should specify parameter names, the code will be easier to understand and you dont have to keep track of parameter position. Also use r in front of path:

import arcpy
from arcpy import env
env.workspace = r"C:\Users\angelaw\OneDrive - TomTom\Resources\Australia\PSMA_MAY_2018\PSMA_Deltas_test\PSMA_MAY_deltas.gdb"

arcpy.AddField_management(in_table="wax_ru", field_name="HN_AW", field_type="TEXT", 
                         field_length=50)

You are providing 50 as the fourth parameter which is field_precision. You can also add empty strings to line up 50 with the right parameter:

arcpy.AddField_management("wax_ru","HN_AW","TEXT","","",50)
  • What does the r do? – AngelaS Jun 15 '18 at 12:42
  • 1
    @AngelaS: Without it some of the \-signs in combination with certain letters can be interpreted as for example a new line = path will not work – BERA Jun 15 '18 at 12:56
  • 1
    @AngelaS About the "r" before the string: stackoverflow.com/questions/2081640/… – Mr. Che Jun 15 '18 at 13:04

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