Calculate Field issue from Python 2 to 3

954
3
04-05-2021 11:02 AM
Labels (3)
Brian_McLeer
Occasional Contributor II

In trying to upgrade code from Python 2 to 3, the below code broke for a calculate field that functioned in 2.x.  I tried putting double quotes around the (' & ') based on some searching, but did not do the trick. 

 

 

!FullName!.split(' & ')[1].split('/')[0]

 

 

The error is:


ERROR 000539: Traceback (most recent call last):
File "<expression>", line 1, in <module>
IndexError: list index out of range
Failed to execute (Calculate Field (4)).

Brian
Tags (1)
0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

check your data, it means that one of the splits doesn't yield what you expect.  

You want the 2nd portion from the first split and the first from the second split.

If you have an entry the doesn't contain  "blah & Blah/done" with an " & "and a "/" then it will fail.

One possible problem is the extra spaces around the ampersand.  "&" is very different from " & "


... sort of retired...
DavidPike
MVP Frequent Contributor

Agree with Dan, this is a data issue and not python version related. It even have 2 spaces either side of the &, is that intended?

JoeBorgione
MVP Emeritus

Here's another vote for a data issue; I won't even go into my usual tirade of special characters in free text fields.  You've already discovered one of the reasons I don't like them....

That should just about do it....
0 Kudos