2

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

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.

  • Thank you! This seemed to do the trick, much appreciated. – Dom B Aug 31 '16 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. – PolyGeo Aug 31 '16 at 22:06
  • 1
    I would modify the code to test whether x is None as opposed to x==None. See this post. – Fezter Aug 31 '16 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. – Dom B Sep 1 '16 at 19:35
3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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