4

I am trying to calculate my End_Streets field within two joined tables. I want to remove the redundant SECONDARYN value from the STREETS field.

" & ".join(!IntersectAndEnds2.Streets!.split(" & ").remove(!StreetSplit2.SECONDARYN!))

Here is a portion of my table:

Joined Table

Here is the error I am receiving when I run the expression in the field calculator.

enter image description here

Error typed out:

ERROR 000539: Error running expression: " & ".join(u"ACORN CT & LARAN RD".split(" & ").remove(u"ACORN CT"))
Traceback (most recent call last):
File "", line1, in TypeError Failed to execute (CalculateField)

2
  • To confirm, you're wanting to remove the value in SECONDARYN from STREETS? So ACORN CT & LARAN RD becomes LARAN RD?
    – Midavalo
    Commented May 12, 2016 at 19:31
  • Are you trying to modify field in a joined table?
    – Midavalo
    Commented May 12, 2016 at 19:50

2 Answers 2

4

You are trying to join a List.remove (returned from .split()), but a List.remove doesn't return anything, so you'd have to remove the item from the list and then join, or if you want to do it inline, I think this would work to exclude what you don't want:

" & ".join(i for i in !IntersectAndEnds2.Streets!.split(" & ") if i <> !StreetSplit2.SECONDARYN!)
5
  • And actually my answer doesn't quite work because arcmap thinks the != is a field rather than "not equal". Commented May 12, 2016 at 20:02
  • 2
    change it to <>
    – Midavalo
    Commented May 12, 2016 at 20:03
  • Thanks. I actually didn't know that Python accepted that. Commented May 12, 2016 at 20:08
  • See docs.python.org/release/2.5.2/lib/comparisons.html - <> is obsolescent however in this case it works as the ! is signifying something else to arcgis
    – Midavalo
    Commented May 12, 2016 at 20:13
  • I have been struggling with this for two days because I'm not a python person. This worked flawlessly. Thank you so much!
    – hherrmann
    Commented May 12, 2016 at 20:41
2

If I understand what you're asking, you want to remove the "ACORN CT & " from "ACORN CT & LARAN RD", leaving just "LARAN RD".

Try this expression

!STREETS!.replace("{} & ".format( !SECONDARYN! ), '').replace(" & {}".format( !SECONDARYN! ), '')

which will leave just "LARAN RD".

I am concerned that you are trying to update a joined table. Your table in the screenshot is called StreetSplit2 but in your expression it looks like the Streets field is in another table called IntersectAndEnds2. You can't update a joined table using the field calculator, you'd need to calculate that field in the actual table (and if necessary perform the join in the other direction).

3
  • 1
    I don't think this would not for the case where the SECONDARYN field value is the last road in the list. Commented May 12, 2016 at 21:59
  • @RichardFairhurst nice spot, have updated around that.
    – Midavalo
    Commented May 12, 2016 at 23:31
  • It also would not work for the case where there is no cross street and only the road itself is listed, which can occur for her data since it includes cul-de-sac, stub and dead end points. Commented May 13, 2016 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.