python - Convert a string field to a number field in arcpy -


i have large (>1000) number of files in there fields containing numbers defined text fields. need have fields containing these values numbers. can add new fields, when i'm failing populate them.

i'm using arcgis 10.1. rows may have values ranging 0-10, , including 1 decimal place, or may empty variable (actually blank, no placeholder).

below python script i'm using 2 of variables (n_ct , n_cfy), , error get. looks problem in how transfer text value decimal conversion.

i'm new scripting, please excuse me if description or word choices unclear.

import arcpy, os, sys arcpy import env decimal import *  arcpy.env.overwriteoutput = true  env.workspace = "c:\users\ouellettems\desktop\ice_data_testarea"  listfcs = arcpy.listfeatureclasses("*")   fc in listfcs:     print str("processing " + fc) # displays file being handled      strnct = "n_ct"   # current, text version of field                  newnct = "nct"    # new, number version want create              strncfy = "n_cfy" # current, text version of field                newncfy = "ncfy"  # new, number version want create               arcpy.addfield_management(fc,newnct,"double")     arcpy.addfield_management(fc,newncfy,"double")      cursor = arcpy.updatecursor(fc)     row in cursor:         row.setvalue(newnct, row.getvalue(decimal(strnct)))         row.setvalue(newncfy, row.getvalue(decimal(strncfy)))         cursor.updaterow(row) 

error mesage:

runtime error traceback (most recent call last): file "", line 23, in file "c:\python27\arcgis10.1\lib\decimal.py", line 548, in new "invalid literal decimal: %r" % value) file "c:\python27\arcgis10.1\lib\decimal.py", line 3844, in _raise_error raise error(explanation) invalidoperation: invalid literal decimal: 'n_ct'

you convert string value integer of float using:

stringa = '12' # convert string integer:  int(stringa) # convert string float  float(stringa) 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -