POST
|
Expression: Classify2(ColorClass) Code Block: def Classify2(ColorClass): for c in ColorClass: if c.count('R') > 0: return 'Red' elif c.count('R') == 0 and (c.count('Y') >= c.count('G')): return 'Yellow' elif c.count('R') == 0 and (c.count('Y') < c.count('G')): return 'Green' Executing (Calculate Field): CalculateField WorkLF_P2 LanduseFeas Classify2(ColorClass) PYTHON_9.3 "def Classify2(ColorClass):\n for c in ColorClass:\n if c.count('R') > 0:\n return 'Red'\n elif c.count('R') == 0 and (c.count('Y') >= c.count('G')):\n return 'Yellow'\n elif c.count('R') == 0 and (c.count('Y') < c.count('G')):\n return 'Green'\n" Start Time: Fri Nov 1 13:52:28 2019 ERROR 000539: Error running expression: Classify2(ColorClass) Traceback (most recent call last): File "<expression>", line 1, in <module> NameError: name 'ColorClass' is not defined Failed to execute (Calculate Field). Failed at Fri Nov 1 13:52:28 2019 (Elapsed Time: 0.01 seconds) So I got it into the code block and now I am attempting debugging. "ColorClass" is not defined, ...but it is the first line of the code Thanks again.
... View more
11-01-2019
11:56 AM
|
0
|
2
|
786
|
POST
|
Hello All, and thanks for any help. I am trying to take this block of Python and insert it into the Field Calculator. What it is supposed to do is take a concatenated field (LF_Concat) and from within that field parse out the number of Greens (G), Yellows (Y), and Reds (R) and then apply a If/Than/elif to number of colors. Right now I am at a loss on how to get it in. I have this too show for it. The parser while it shows VB is actually in Python (I maybe slow, but I ain't that slow) I suspect that the delineatorList should be changed to the concatenated field (LF_concat) but I am lost beyond that. Thanks, Chris delineatorList = [" ", ".", ","] ColorClass = ['GGGY','GGYY','GYYR'] for letters in ColorClass: #print letters, " G = ", letters.count('G') #print letters, " Y = ", letters.count('Y') #print letters, " R = ", letters.count('R') Count_G = letters.count('G') Count_Y = letters.count('Y') Count_R = letters.count('R') if Count_R > 0: print "Red" elif Count_R == 0 and Count_Y >= Count_G: print "Yellow" elif Count_R == 0 and Count_Y < Count_G: print "Green"
... View more
10-30-2019
12:38 PM
|
0
|
5
|
823
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|