AnsweredAssumed Answered

Field Calculator with Python Code Block runs but returns null

Question asked by nbanerjee on Nov 11, 2019
Latest reply on Nov 11, 2019 by nbanerjee



I have a Python expression that utilizes a code block that I am trying to run as a field calculation (manual or with Field Calculator geoprocessing tool).  The code runs without issue, but returns nulls even if I hard-code the return value to a simple string.  I have tried going through line by line to better understand where/why it is not working.  Best I can tell is it fails once I try to round a number.  The code does include some lists, dictionaries, and loops, but it works fine when I run in an independent Python IDE with hardcoded input values.


In the code snippet below, Ive hard coded the function just to return a "TEST" (see near bottom), but it return null.  If I take out the line with round statement it does at least return "TEST". I think Ive checked all my indentation, but cant think of anything else that may be causing the issue


Does field calculator have any limitations with lists, loops, etc.?  Any ideas what may be causing this?


Any thoughts would be greatly appreciated!






-------------------- Code Snippet ---------

def Calc(ScrA, ScrB, ScrC, ScrD, ScrE, ScrF, ScrG, ScrH, ScrI, ScrJ, ScrK, ScrL, ScrM, multN, multO, multP, multQ, ScrTot):
  dicComMult={multN:"N", multO:"O", multP:"P",multQ:"Q"}
  maxMult = max(dicComMult)
  if maxMult > 1:
    maxMultCom = dicComMult[max(dicComMult)]
    ScrMult = round(ScrTot - (ScrTot / maxMult),1)
    ScrMult = 0


  lstCom = [("A", ScrA), ("B", ScrB), ("C", ScrC), ("D", ScrD), ("E", ScrE), ("F", ScrF), ("G", ScrG), ("H",ScrH), ("I", ScrI), ("J", ScrJ), ("K", ScrK), ("L", ScrL), ("M", ScrM), (maxMultCom,ScrMult)]


  for Com in lstCom:
  return "TEST"


Example Field Calculator that returns null