Hi all,
Working on converting a stand alone script from python 2 to 3. When I run it, I get an error "NameError: name 'numRecords' is not defined" . I am having issue trying to get numRecords defined. Any idea on what is causing the issue? Ran fine in python 2.
Below is section of script related to error.
#Find both Frequency tables in the aprx and set them as variables
FreqTable = m.listTables("Freq")
Freq1Table = m.listTables("Freq1")
#Add definition query to remove records in freq tables with blank values.
for lyr in m.listTables(aprx):
if lyr.name == "Freq":
lyr.definitionQuery = "AGUSETYPE <> '' AND MUPOLYGON_MUSYM <> ''"
for lyr in m.listTables(aprx):
if lyr.name == "Freq1":
lyr.definitionQuery = "AGUSETYPE <> ''"
#Reference page layout elements
lyt = aprx.listLayouts()[0]
if not lyt.mapSeries is None:
ms = lyt.mapSeries
lyt.mapSeries.refresh()
if ms.enabled:
ms.currentPageNumber = ms.getPageNumberFromName(PIN)
#Build selection set
for t in FreqTable:
numRecords = int(arcpy.management.GetCount(t).getOutput(0))
print(str(numRecords))Below is "Freq" defined, which is within script near the beginning.
#Create Frequency table using (AGUSETYPE, MUPOLYGON_MUSYM and Sum byACRES). Then Add Frequency table to aprx.
arcpy.analysis.Frequency(r'memory\aguse_soil',r'memory\Freq',"AGUSETYPE;MUPOLYGON_MUSYM","ACRES")
Freq = arcpy.management.MakeTableView(r'memory\Freq')