3

I am trying to copy the values from one column within my attribute table (!roomName!) over to another column (!spaceDiscriminator!). I understand how to do an easy field calc over for all the values but the problem is, I only want the rows in !roomName! that have values to copy over. If !roomName! contains a Null row then I do not want it copying over, instead I want the original value in !spaceDiscriminator! to remain and not get edited. I cannot figure out how to do this adequately. I have attached my code below:

In the first if statement I have tried many alternative scenarios. If x == None: seems to be the one that accurately selects the Null fields I don't want copying over. return None still edits the !spaceDiscriminator! field however. I've tried to use continue there but it throws and error. Is there any simple statement I can use there that basically says, "if the value is none/Null continue to the next row and leave original !spaceDiscriminator! value".

enter image description here

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Aug 31, 2016 at 21:21

2 Answers 2

5

The code you seek would be something like this:

testme(!roomname!,!spaceddiscriminator!)
def testme(x,y):
 if x is None:
 return y
 else:
 return x

As you can see you can pass more than one field value into your function, in your case the value from the very field you are updating.

answered Aug 31, 2016 at 21:33
4
  • Thank you! This seemed to do the trick, much appreciated. Commented Aug 31, 2016 at 21:37
  • 1
    @DomB The way to show appreciation for an answer is to upvote it and/or check the green Accept mark next to it. Your rep may prevent you from doing one or both just yet. Commented Aug 31, 2016 at 22:06
  • 1
    I would modify the code to test whether x is None as opposed to x==None. See this post. Commented Aug 31, 2016 at 22:17
  • Thank you both. I've also checked the green accept mark as I'm still too low level to upvote. I've updated to is as that works properly. Commented Sep 1, 2016 at 19:35
3

Just Select by Attributes where [RoomName] is not null, then do your simple calculation. Should only operate on selected rows.

answered Aug 31, 2016 at 21:37

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.