AnsweredAssumed Answered

ModelBuilder - Convert VB Script to Python Coding HELP!!

Question asked by MDASteve on Jan 22, 2020
Latest reply on Jan 22, 2020 by jborgion

Hi everyone and thank you in advance for all your answers. 


First thing first - I am a beginner in Python and I might ask stupid questions. Hopefully this won't be one of them. 


We have an old tool that works perfectly in ArcMap but recently we had no choice but convert it to PRO. I ran the analyse tool in geoprocessor to open the "old toolbox" in PRO and I can edit the model. After going through all the tools and testing I found that some of the "Calculate Field" tools are in VB. So these need to change it to Python for it to run in PRO. 


In short, the tool needs to find the number (typically "55" or "60" always a double number) in a column/field (let's call it "Address") and populate the "Number" field/column with the number. 

The current strict is as follw:

 Number = 
is_string(!MAX_%Field Name%!)


Code Block

def is_string(s):
   if isinstance(s, basestring) == True:
     num = ''

     for i in s:
       if i in '01234567890':
     integer = int(num)
return integer
if isinstance(s, basestring) == False:
return s


Any help on this would be great thank you.