2

Am interested in combining ClASS1 and SUBCLASS1 to form the one combined class. I wrote the expression as follows "() ()" format( !CLASS1!replace(" "","" ),( !SUBCLASS1!replace(" "","" ))as shown in the Image[![field to be combined and expression] [![enter image description here] enter image description here

but after executing I get the following error message error message

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jun 30, 2017 at 14:36
1
  • 1
    Please always present errors as text rather than pictures. Commented Jun 30, 2017 at 21:44

2 Answers 2

2

If spaces before or after the values in CLASS1 and SUBCLASS1 are the only issue, the expression could be simplified by using the strip method instead:

"{} {}".format(!CLASS1!.strip(), !SUBCLASS1!.strip())
answered Jun 30, 2017 at 14:56
0

As the error states, your syntax is wrong. I assume you want to replace spaces with commas. Try this line for your expression:

"{} {}".format(!CLASS1!.replace(" ",","),(!SUBCLASS1!.replace(" ",","))

EDIT:

Since I now see what your data looks like, I guess the .strip() option is the nicer choice. If you still want to use the .replace() function try this:

"{} {}".format(!CLASS1!.replace(" ",""),(!SUBCLASS1!.replace(" ",""))
answered Jun 30, 2017 at 14:42
3
  • Should 0 and 1 be in between the curly brackets? like this: "{0}{1}"... will still work if the curly brackets are empty? Commented Jun 30, 2017 at 14:55
  • the {0} and {1} are only necessary, if you refer to the place markes in a different order. example: "{0} {1} {0}".format("A", "B") will return "A B A". so in this case they are not necessary. Commented Jun 30, 2017 at 14:57
  • @DelonixR. if no indices are used in the expression, format will use the parameters in the order they are entered. Commented Jun 30, 2017 at 14:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.