ArcMap – Extract Numbers from String Field Using Python Parser

arcgis-desktopfield-calculatorlooppython-parserstring

enter image description here

I am trying to calculate field test2 with only the numeric values from a string field test. The entire script is like:


def makestr(test)
     list=[]
     for s in test:
         if s.isdigit():
             list.append(s)
     for a in list:
         str=''.join(list)

But I keep getting an error:

enter image description here

Any ideas?

Best Answer

Try this:

def makestr(test):  # Add colon
     numlist = []   # Don't use name "list"
     for s in test:
         if s.isdigit():
             numlist.append(s)
     return ''.join(numlist)  # Return a value
Related Question