Select to view content in your preferred language

New to Python

540
3
02-06-2019 09:00 AM
ChrisKendrick
Emerging Contributor

I am new to Python and I am trying to write a code in Field calculator to update a field using another field in attribute table.

Could someone please help me with this?

Thanks,

Chris

0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus

well  you might want the Python‌ space, so I would move this question if I could, but a Share might do

JoshuaBixby
MVP Esteemed Contributor

Assuming you read Calculate Field—Data Management toolbox | ArcGIS Desktop , what part of the syntax are you having difficulties with specifically?

BenBond
Occasional Contributor

You will need to write a function to do what you want and then call that function from the field calculator.

 

Arcmap: click the show codeblock check box and paste your function in the Pre-Logic Script code box.

Pro: paste your function in the code block.

 

Make sure the expression type is set to python.

 

Then pace the field you want to call in the expression.

 

So for example this is a simple script that will run a regular expression on the specified field and return any number at the beginning of the field.  For me I use it to collect house numbers at the front of an address.

 

 

So as you can see this will calculate for the field HOUSENUM.  I pass the field LSN to the regex function that I defined in the code block.  It runs some regular expression stuff and returns the text variable which is stored in the field HOUSENUM.