Add Field decided to add an underscore to the field name

I created a script to build a template geodatabase. The code creates a geodatabase, adds a few domains, creates a feature class, adds some fields to the feature class and sets their domains, and finally sets all the default values for the fields.

When you add a field with a reserved name by code or through the tool, it automatically adds an underscore to it. In your desktop test, were you adding that field to a feature class stored in that particular geodatabase?

By using the tool within ArcDesktop, the add field tool properly added a field named "Public" with no underscore.

The following is the code snippet ArcDesktop used:

# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script
# The following inputs are layers or table views: "UTC_Parcels"
arcpy.AddField_management("UTC_Parcels","Public","TEXT","#","#","#","#","NULLABLE","REQUIRED","#")

This doesn't answer why Python would put an underscore on the field name, however.

Does your code add an underscore if you name the field something else? 'Public' sounds like a keyword. Considering you're setting domains there might be some conflict there, but that's just speculation on my part.

The word "Public" does appear on the ISO/ANSI SQL99 reserved words and the T-SQL reserved words list, but that doesn't really explain to me why Python changed it or why running the tool from within ArcDesktop worked fine...

When you add a field with a reserved name by code or through the tool, it automatically adds an underscore to it. In your desktop test, were you adding that field to a feature class stored in that particular geodatabase?