AnsweredAssumed Answered

Arcpy - Stripping out strings in a field seperated by comma (with nulls)

Question asked by timdun on Aug 8, 2018
Latest reply on Aug 8, 2018 by Dan_Patterson

Hi all,

I have a feature class which has 1 field which are hyperlinks to photos:

e.g. [PHOTO] : C:\temp\photo1.jpg, c:\temp\photo2.jpg, c:\temp\photo3,jpg

All one string in the PHOTO field, separated by commas.

I want to strip out each hyperlink and update 9 Hyperlink fields in the feature class: [HYPERLINK1], [HYPERLINK2], [HYPERLINK3]….[HYPERLINK9].

I thought it would be easy going something like this:


with arcpy.da.UpdateCursor(fc, ['PHOTOS', 'HYPERLINK1', 'HYPERLINK2', 'HYPERLINK3', 'HYPERLINK4', 'HYPERLINK5', 'HYPERLINK6', 'HYPERLINK7', 'HYPERLINK8', 'HYPERLINK9']) as cursor:
    for row in cursor:
        row[1] = row[0].split(",")[0]
        row[2] = row[0].split(",")[1]
        row[3] = row[0].split(",")[2]
        row[4] = row[0].split(",")[3]



But I'm getting an out of index range as the [PHOTOS] field has some nulls.

And also the [PHOTO] field can have between NULL and 9 Hyperlink strings separated by commas.

So the above code would work if there were 9 strings separated by commas.

Is there a way to get around this?


ArcGIS v10.6, windows 10