Update Field from Multiple Field(s)

2445
12
09-19-2016 11:00 AM
ModernElectric
Occasional Contributor III

I have been looking around the internet all morning to figure out how to write a Python script to accomplish what I need to do, and so far, I am not finding what I need. Need to see if someone can start me in the correct direction.

I have (2) text fields:

   ACALARA TYPE and ACALARA MODEL with coded meter type attributes

Another field:

   ACALARA METER TYPE will hold the actual Meter Type 

The data in the first two fields is held in a different database and I have a Python script built that will take that data and update these Feature Class Fields. 

What I need to do is build a second python script that is composed of an if/else statement.

EXAMPLE:

   If ACALARA TYPE = 75 and ACALARA MODEL = 130

      Then the ACALARA METER TYPE field will update to show "CEN3S4S20"

   If ACALARA TYPE = 109 and ACALARA MODEL = 2

      Then the ACALARA METER TYPE field will update to show "UMT2.1"

There are around 2 dozen other combinations with additional Meter Type outputs that I will have to include

Figuring out how to write this code will help with other Feature Classes that I have been updating manually.

Thank You 

0 Kudos
12 Replies
ModernElectric
Occasional Contributor III

The I get: "RuntimeError: Unspecific error"

Says something about line 20

Does the code and everything look okay? I added your suggestion and nothing.

DanPatterson_Retired
MVP Emeritus

start by fixing the first line an putting the 'fc' variable into raw format as Darren notes.  And on a side note, if you continue to use folders and filenames with spaces and other characters ... like dashes - ... you will continue to have problems.

'Says something about line 20'  .... write it down, screen grab it, but at least report it.  Error messages noted for a particular line are often the result of errors further on up the script, like the file name, because line 20 expects to use 'rows' but if the filename or fields are no good, the erro cascade begins.

0 Kudos
curtvprice
MVP Esteemed Contributor

Line 20 is where you call my function. This function seems to be working correctly though. 

>>> proc(75, 130)
'CEN3S4S20'
>>> proc(109, 2)
'UMT2.1'

>> proc(109,4)
Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<string>", line 10, in proc
Exception

Note, my code is assuming the actype and acmodel fields are numeric and your output field is string.

I will update the code to more gracefully handle unhandled combinations, there is a syntax error in my raise statement.

UPDATE: after my fix:

>>> proc(109,4)
Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<string>", line 12, in proc
Exception: Unhandled case: proc(109, 4)
>>>

0 Kudos