Mid() function in Python

38556
11
10-31-2019 10:55 AM
SLouq
by MVP Regular Contributor
MVP Regular Contributor

I am trying to use the Python Mid() function to return strings starting at the 5th character.

I have tried

!STR_NAME!.Mid(5:20)

but that gives me a traceback error

Can someone point me in the right direction?

Thanks

Tags (2)
0 Kudos
11 Replies
DanPatterson_Retired
MVP Emeritus

do it manually (assuming that you have to do this whole process many times)

get it right, then put in the model in order to rule out other stuff like overwriting outputs etc etc.

The error message would also help.

Also python is 0 based so a[:5] will slice the 0, 1, 2, 3, 4 characters, hence :5 means beyond the 5th character

a[5:10] means beyond the 5th and up to, but not including the 10th (5, 6, 7, 8, 9), that is, 5 characters (10 - 5)

SLouq
by MVP Regular Contributor
MVP Regular Contributor

Thanks for helping me guys!

0 Kudos