Python script to append field.length(254) to field.length(25)

09-28-2017 06:42 AM
New Contributor

Need a python script to help with an Append.

My input field length is 254 and my output field length is 25.

So I want the script to still append the data to the new field but can cut it off when it reaches 25 characters.

Is the anyway to do this?

Sample of my script:

import arcpy, sys, os

# Arguments
input_data = arcpy.GetParameterAsText(0)
template = arcpy.GetParameterAsText(1)

arcpy.Append_management(input_data,template,"NO_TEST", "", "")

But this gives me the error.

Tags (1)
0 Kudos
2 Replies
MVP Emeritus

can we assume you have tried it and it fails with some error message

did you also try to fix the situation by adding a new field to the 25 char table and make it the right size, followed by a simple field calculation to bring over the values into the new field?  Then dump the short width field and use the new field in the append.

Any information on what you have tried and what their results were would be useful, since there are obvious workarounds.

0 Kudos
Esri Esteemed Contributor

Simply assigning the long field to the shorter field my yield errors or truncate in a way you don't want. The field calculation that Dan refers to could be as simple as (using Python syntax)