Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

arcpy.CalculateField_management) is not passing variable

$
0
0
Running as python script within toolbox in ArcGIS 10.1. Trying to say that if file is empty, populate the fields "TypeName","PERCENTAGE", "Region" with the following values: nameVariable, 0, "Georgia", otherwise, populate the table fields "Region" with "Georgia" and the field "TypeName" with "Goldfish". I cannot seem to populate the TypeName field with a variable. What am I doing wrong. I have spent two days on this and I cannot figure it out!

Code:

import os.path
import arcpy
import arcgisscripting

myList = ("Fish", "Reptile","Aracnid", "Other")
geoLoc = "C:\\Data\\TempData.gdb\\"

for variablefile in myList:

#  Assigning variables

    species = geoLoc + (variablefile)+ "_Buffer"

# setting nameVariable
    if variablefile == "Fish":
        nameVariable = "Goldfish"
    elif variablefile == "Reptile":
        nameVariable = "Tree frog"
    elif variablefile == "Aracnid":
        nameVariable = "Black widow"
    else:
        nameVariable = "Household pet"

    addRow =arcpy.da.InsertCursor(species,("TypeName","PERCENTAGE", "Region"))
    result = int(arcpy.GetCount_management(species).getOutput(0))

    if result == 0:
        addRow.insertRow((nameVariable, 0, "Georgia"))
    else:
        arcpy.CalculateField_management(species, "Region", "\"Georgia\"", "PYTHON", "")
        arcpy.CalculateField_management(species, "TypeName", 'nameVariable', "PYTHON", "")
#        arcpy.CalculateField_management(species, "Name", "\"Goldfish\"", "PYTHON", "")  Works but doesn't use variable name
    exit


I get the following error message:

ExecuteError: ERROR 000539: Error running expression: commonName
Traceback (most recent call last):
File "<expression>", line 1, in <module>
NameError: name 'commonName' is not defined


Pretty sure it is failing at nameVariable (bold).

Thanks in advance.

Viewing all articles
Browse latest Browse all 2485

Latest Images

Trending Articles



Latest Images