Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to simply add a string in front of a group of numbers from another field in a new field. The filed I'm using update cursor in is GIS_ID_PAM and I'm trying to bring over numbers from a column called PointID. My intent is to get "PAM - " in front of the numbers from the PointID column. Here's what I have that isn't working.

        urows = arcpy.UpdateCursor(fc)
        for urow in urows:
            urow.DateImport = str(timestr)
            urow.GIS_ID_PAM = "PAM - " + [PointID]
            urows.updateRow(urow)
share|improve this question
    
Is GIS_ID_PAM of field type Text or something else? –  Martin Mar 13 at 14:43
1  
If you are using ArcMap >= 10.1, you should investigate the data access module. Much better cursor support. –  Paul Mar 13 at 22:15
add comment

1 Answer 1

up vote 9 down vote accepted

If PointID is one of the fields of fc, you can either use

urow.GIS_ID_PAM = "PAM - " + str(urow.PointID)

or

urow.setValue("GIS_ID_PAM", "PAM - " + str(urow.getValue("PointID"))

str() is not necessary if your PointID field is already of type "text".

EDIT : example with .format() (based on Paul's comment)

urow.setValue("GIS_ID_PAM", "PAM - {0!s}".format(urow.getValue("PointID"))
share|improve this answer
1  
Instead of using string concatenation, you might want to use .format(). It has built in string casting for variables and can be a lot simpler when concatenating strings and variables. –  Paul Mar 13 at 22:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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