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".
2 Answers 2
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.
-
Thank you! This seemed to do the trick, much appreciated.DEB– DEB2016年08月31日 21:37:51 +00:00Commented 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.2016年08月31日 22:06:44 +00:00Commented Aug 31, 2016 at 22:06
-
1
-
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.DEB– DEB2016年09月01日 19:35:16 +00:00Commented Sep 1, 2016 at 19:35
Just Select by Attributes where [RoomName] is not null, then do your simple calculation. Should only operate on selected rows.
Explore related questions
See similar questions with these tags.