AnsweredAssumed Answered

Need help with syntax in UpdateRow parameter variables

Question asked by tundra on Jan 7, 2016
Latest reply on Jan 8, 2016 by tundra

I am new at python coding and I am trying to convert a script to a function.  The script that works is commented out at the bottom.  However, the problem I run into is trying to convert the values in the script at the bottom to variables that I can pass to a function.  I am trying to update the values of the field 'OperatingPressure' with the values that exist in the field 'MAOP'.  I can't get the correct syntax right for the values that will make up the variables of 'aWhereClause' and 'aUpdateExpression'.  Any help would be greatly appreciated.

 

import arcpy, os, string, logging
from arcpy import env

arcpy.env.workspace = "C:/DuluthGIS/SchemaUpdate/SDESchemaTest.gdb"
workspace = "C:/DuluthGIS/SchemaUpdate/SDESchemaTest.gdb"      #workspace

#This is the function that is my final product.
#def queryUpdateField(iList):
  #aTable = iList[0]
  #aWhereClause = iList[1]
  #aUpdateField = iList[2]
  #aUpdateExpression = iList[3]

  #Search for records in table
  # rows = arcpy.UpdateCursor(aTable,aWhereClause)

  # for row in rows:
  # row.setValue(aUpdateField,aUpdateExpression)
  # rows.updateRow(row)
  # del rows, row

#Call function above
#queryUpdateField([workspace + "/Gas/gasDistributionMain",'"MAOP" >= 0',
#'"OPERATINGPRESSURE"','row.getValue("MAOP")'])
#---------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------


#This script is trying to test my variables and get them right before I put them 
#in the line above to call the function
aTable = workspace + "/Gas/gasDistributionMain" # this works
aWhereClause = "'" + '"' + "MAOP" +'"' +" >= 0'"  #fails needs correct syntax
aUpdateField = "OPERATINGPRESSURE" # this works
aUpdateExpression = "row.getValue(" + '"MAOP"'+ ")"  #fails needs correct syntax
print aWhereClause  #debug
print aUpdateExpression  #debug
rows = arcpy.UpdateCursor(aTable,aWhereClause)

for row in rows:
  row.setValue(aUpdateField,row.getValue("MAOP"))
  rows.updateRow(row)
del rows, row
#------------------Script that works that I am trying to convert to a function above----------------------------
# This works!!!
# rows = arcpy.UpdateCursor(workspace + "/Gas/gasDistributionMain",'"MAOP" >= 0')


# for row in rows:
  # row.setValue("OPERATINGPRESSURE",row.getValue("MAOP"))
  # rows.updateRow(row)
# del rows, row

Outcomes