Select to view content in your preferred language

Python in Field Calculator

2126
3
02-02-2014 12:39 AM
MatthiasJessen
Deactivated User
Hello,

i try to use the index position of a field for an if-clause in the field calculator.

gesamt =
function(arcpy.fieldInfo.findFieldByName(!gesamt!))


Codeblock:
def function(index):
 if (index > 30):
  ergebnis =  (!Join_Count! + !Join_Count_1!)
  return ergebnis
 else:
  return 99


Result:
[ATTACH=CONFIG]31051[/ATTACH]

This way or syntax is probably totaly wrong and i am grateful for any advise or solution.

Thank you
Tags (2)
0 Kudos
3 Replies
Luke_Pinner
MVP Regular Contributor
The fieldInfo object is a property of a Describe object. Its class definition is in the arcpy package, but you don't use it from there (how does arcpy know what layer you are referring to?). See the 1st example in the help.

Try:
arcpy.Describe(layer).fieldInfo.findFieldByName(!gesamt!))
0 Kudos
RichardFairhurst
MVP Alum
The fieldInfo object is a property of a Describe object. It's class definition is in the arcpy package, but you don't use it from there (how does arcpy know what layer you are referring to?). See the 1st example in the help.

Try:
arcpy.Describe(layer).fieldInfo.findFieldByName(!gesamt!))


You also have to pass in the !Join_Count! and Join_Count_1! fields through the expression to the codeblock from the same layer.  A cursor pair might be easier if this is for a join table calculation with a runtime assigned layer set.

Try
function(arcpy.Describe(layer).fieldInfo.findFieldByName(!gesamt!), arcpy.Describe(layer).fieldInfo.findFieldByName(!Join_Count!), arcpy.Describe(layer).fieldInfo.findFieldByName(!Join_Count_1!)))


def function(index, Join_Count, Join_Count_1)
0 Kudos
MatthiasJessen
Deactivated User
Thank you. We solved it with an extern python script and the FieldInfo
0 Kudos