Select to view content in your preferred language

ModelBuilder VB to Python Conversion

1084
4
Jump to solution
10-28-2022 01:38 PM
CTalbot
Occasional Contributor

Hello,

I'm writing for some assistance in troubleshooting converting an old Model from VB script to Python. 

The specific area giving me trouble is a Calculate Field Expression 

here's what I started with:

=[AREA_CODE] & Replace ([BIDDER_PERCENTAGES_TABLE_SELECT_BLOCK_NUMBER], " ", "")

this gave error00539 'Replace' is not defined

Here's a couple things I attempted:

!AREA_CODE! & Replace (!BIDDER_PERCENTAGES_TABLE_SELECT_BLOCK_NUMBER!, " ", "")

   ^same error code

!AREA_CODE! + replace (!BIDDER_PERCENTAGES_TABLE_SELECT_BLOCK_NUMBER!, " ", "")

   ^same error code

!AREA_CODE! + (!BIDDER_PERCENTAGES_TABLE_SELECT_BLOCK_NUMBER!, " ", "")

   ^error 00539-TypeError: can only concatenate str (not "tuple") to str

!AREA_CODE! + tuple(!BIDDER_PERCENTAGES_TABLE_SELECT_BLOCK_NUMBER!, " ", "")

   ^error 00539-TypeError: tuple expected at most 1 arguments, got 3

!AREA_CODE! + [tuple(!BIDDER_PERCENTAGES_TABLE_SELECT_BLOCK_NUMBER!, " ", "")]

   ^error 00539-Syntax error: invalid syntax

 

I'm at a bit of a loss as to what to try next

please let me know what you think

 

Sincerely,

Christopher

@arcgis_python 

 

 

 

Sincerely,
Christopher
0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

Assuming that you want to concatenate the two fields and remove spaces  in the longer field name.  "str"ing both fields in case a number to text conversion is necessary.

str(!AREA_CODE!) + str(!BIDDER_PERCENTAGES_TABLE_SELECT_BLOCK_NUMBER!).replace(" ", "")

 


... sort of retired...

View solution in original post

4 Replies
Brian_Wilson
Honored Contributor

I am thinking the REPLACE part is doing nothing but maybe convert a numeric field to a string The str() will pretty much turn anything into a string, so this seems like it would be safe.

 

str(!AREA_CODE!) + str(!BIDDER_PERCENTAGES_TABLE_SELECT_BLOCK_NUMBER!)

 

CTalbot
Occasional Contributor

Hello, thank you much!

Sincerely,
Christopher
0 Kudos
DanPatterson
MVP Esteemed Contributor

Assuming that you want to concatenate the two fields and remove spaces  in the longer field name.  "str"ing both fields in case a number to text conversion is necessary.

str(!AREA_CODE!) + str(!BIDDER_PERCENTAGES_TABLE_SELECT_BLOCK_NUMBER!).replace(" ", "")

 


... sort of retired...
CTalbot
Occasional Contributor

Hello, Thank You much! 

Sincerely,
Christopher
0 Kudos