3

I know this question has been asked before in different fashions, but I can't seem to get my python script to work despite looking at all the relevant questions I could find.

I am simply trying to populate an attribute field based on the conditions of another attribute field. Specifically I have one field that labels various projects under different headings (example: easement, BPS, donated etc.)

I want to calculate the values in a new field to group these into one of three headings (Donated Easement, Purchased Easement, BPS). However I can't get the python to work and I would rather not do it by hand. Here is the code I ran just to try to get one label type recalculated.

pre-logic:

def reLabel(typeLabel):
  if typeLabel == 'BPS Easement':
    return 'BPS'
  else:
    return 'Other'

Label2:

reLabel(!Type_Label!)

Table

  • this looks OK (except indentation,but I guess this is correct in your code). note that the comparison is case sensitive. by the way, have you tried to select and update your field, this wold be a quick workaround with only 3 categories and you would directly see if the selection is not doing what you expect – radouxju Feb 2 '16 at 21:08
  • Yes, the indentation is not where I am getting the error. I keep getting an error that says "Failed to execute. Parameters are not valid." and another "Error 000735: Input Table: Value is required" – TsugaGrove Feb 3 '16 at 13:31
  • have you tried my workaround ? with your present description of the issue there is little we can do to help. Maybe you could add a snapshot of your table. – radouxju Feb 3 '16 at 13:51
  • Yes, the workaround would work, but I would like to sort out how to do this through Python if possible. I added a screenshot above. Thanks. – TsugaGrove Feb 3 '16 at 14:00
1

Your indentation is off, you're missing an indent on the "Else" line:

def reLabel(typeLabel):
  if typeLabel == 'BPS Easement':
    return 'BPS'
  else:
    return 'Other'
|improve this answer|||||
  • The indentation is not where I am getting the error. I keep getting an error that says "Failed to execute. Parameters are not valid." and another "Error 000735: Input Table: Value is required" – TsugaGrove Feb 3 '16 at 13:38
0

I ended up selecting all the features in the layer and exporting to a new layer. The python script worked fine after that. Not sure what the issue was but this resolved it.

|improve this answer|||||

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.