Python expressions in field calculator

285
4
Jump to solution
09-19-2019 03:30 AM
HelenCooper
Occasional Contributor III

Hi all, 

I'm transitioning from ArcMap to ArcGIS Pro - no experience of Python but would like to learn.

I'm trying to run a very simple string function to remove four digits at the end of text field. In ArcMap VB Script I would do the following:

Left([FieldName],Len([FieldName])-4)

I can't see how to do the same in Python.

There seem to be relatively few examples here: 

Calculate Field examples—Help | ArcGIS Desktop 

and the link to the build in functions of Python returns a 404 error.

Is there a good resource that sets out the functions and arguments for Python in ArcGIS?  I have googled but can't find what I'm looking for!

Thanks in advance for any help, 

Helen

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Esteemed Contributor

perhaps

a = '1234567890'

a[:-4]
'123456'

# ---- if 'a' were the field name, you would use !a![:-4] in the field calculator‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

4 Replies
DanPatterson_Retired
MVP Esteemed Contributor

perhaps

a = '1234567890'

a[:-4]
'123456'

# ---- if 'a' were the field name, you would use !a![:-4] in the field calculator‍‍‍‍‍‍‍‍‍‍‍‍
DanPatterson_Retired
MVP Esteemed Contributor

I find the python docs succinct and complete

3. An Informal Introduction to Python — Python 3.7.4 documentation 

HelenCooper
Occasional Contributor III

Perfect, I will take a look, very many thanks.

0 Kudos
HelenCooper
Occasional Contributor III

Thanks Dan, 

That worked perfectly - any suggestions on good resources for learning?

Thanks, 

Helen

0 Kudos