<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: NameError: name ' ' is not defined. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/nameerror-name-is-not-defined/m-p/1326023#M68858</link>
    <description>&lt;P&gt;I'd love to just load the entire script into my debugger here and run it, can you post the whole thing? Obviously redact private information if you need to.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Sep 2023 17:29:23 GMT</pubDate>
    <dc:creator>Brian_Wilson</dc:creator>
    <dc:date>2023-09-06T17:29:23Z</dc:date>
    <item>
      <title>NameError: name ' ' is not defined.</title>
      <link>https://community.esri.com/t5/python-questions/nameerror-name-is-not-defined/m-p/1323611#M68853</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Working on converting a stand alone script from python 2 to 3. When I run it, I get an error &lt;EM&gt;&lt;STRONG&gt;"NameError: name 'numRecords' is not defined"&lt;/STRONG&gt; &lt;/EM&gt;. I am having issue trying to get numRecords defined. Any idea on what is causing the issue? Ran fine in python 2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is section of script related to error.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt; #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 &amp;lt;&amp;gt; '' AND MUPOLYGON_MUSYM &amp;lt;&amp;gt; ''"	

        for lyr in m.listTables(aprx):
            if lyr.name == "Freq1":
                lyr.definitionQuery = "AGUSETYPE &amp;lt;&amp;gt; ''"


        #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))&lt;/LI-CODE&gt;&lt;P&gt;Below is "Freq" defined, which is within script near the beginning.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;        #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')&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 29 Aug 2023 18:42:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/nameerror-name-is-not-defined/m-p/1323611#M68853</guid>
      <dc:creator>ScoutStanley</dc:creator>
      <dc:date>2023-08-29T18:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: NameError: name ' ' is not defined.</title>
      <link>https://community.esri.com/t5/python-questions/nameerror-name-is-not-defined/m-p/1323646#M68854</link>
      <description>&lt;P&gt;This feels like a fragment of a larger script, if line&amp;nbsp; 27 runs then numRecords will be defined and the only other place it's referenced is line 28. If line 27 ran then line 28 should run. So there is no place where the error will trip you up?? Does the error message include a line number? (I test in Visual Studio Code, always.)&lt;/P&gt;&lt;P&gt;For example if I extract these lines they run fine even though I have no FreqTable until the (unindented) print throws an error and it shows be the problem is on line 4&lt;/P&gt;&lt;LI-CODE lang="python"&gt;FreqTable = m.listTables("Freq")
for t in FreqTable:
    numRecords = int(arcpy.management.GetCount(t).getOutput(0))
print(numRecords)

NameError                                 Traceback (most recent call last)
      2 for t in FreqTable:
      3     numRecords = int(arcpy.management.GetCount(t).getOutput(0))
----&amp;gt; 4 print(numRecords)

NameError: name 'numRecords' is not defined&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2023 19:27:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/nameerror-name-is-not-defined/m-p/1323646#M68854</guid>
      <dc:creator>Brian_Wilson</dc:creator>
      <dc:date>2023-08-29T19:27:34Z</dc:date>
    </item>
    <item>
      <title>Re: NameError: name ' ' is not defined.</title>
      <link>https://community.esri.com/t5/python-questions/nameerror-name-is-not-defined/m-p/1325634#M68855</link>
      <description>&lt;P&gt;Yes, this is fragment of a larger script, but I have included all information related to numRecords. The error message includes line number 27, which is below. The error is &lt;EM&gt;&lt;STRONG&gt;"numRecords" not defined&lt;/STRONG&gt;&lt;/EM&gt;, which is confusing me because in the script I have it clearly defined, so I am trying to figure out where I am doing something wrong.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;numRecords = int(arcpy.management.GetCount(t).getOutput(0))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2023 20:54:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/nameerror-name-is-not-defined/m-p/1325634#M68855</guid>
      <dc:creator>ScoutStanley</dc:creator>
      <dc:date>2023-09-05T20:54:13Z</dc:date>
    </item>
    <item>
      <title>Re: NameError: name ' ' is not defined.</title>
      <link>https://community.esri.com/t5/python-questions/nameerror-name-is-not-defined/m-p/1325638#M68856</link>
      <description>&lt;P&gt;Have you tried&lt;/P&gt;&lt;P&gt;numRecords = arcpy.management.GetCount(t) # don't need getOutput(0) or int()&lt;/P&gt;&lt;P&gt;print(numRecords) # dont need str()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2023 21:11:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/nameerror-name-is-not-defined/m-p/1325638#M68856</guid>
      <dc:creator>Brian_Wilson</dc:creator>
      <dc:date>2023-09-05T21:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: NameError: name ' ' is not defined.</title>
      <link>https://community.esri.com/t5/python-questions/nameerror-name-is-not-defined/m-p/1325968#M68857</link>
      <description>&lt;P&gt;I tested that recommendation. It crashes a couple lines down in the script where I 1st reference it with &lt;EM&gt;&lt;STRONG&gt;NameError: name 'numRecords' is not defined&lt;/STRONG&gt;&lt;/EM&gt;... However, when it runs it does not complete result of my "print (numRecords) statement that I want included. Below is result error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ScoutStanley_0-1694015418081.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/79988iCBF8A6F63B022ACC/image-size/large?v=v2&amp;amp;px=999" role="button" title="ScoutStanley_0-1694015418081.png" alt="ScoutStanley_0-1694015418081.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 15:51:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/nameerror-name-is-not-defined/m-p/1325968#M68857</guid>
      <dc:creator>ScoutStanley</dc:creator>
      <dc:date>2023-09-06T15:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: NameError: name ' ' is not defined.</title>
      <link>https://community.esri.com/t5/python-questions/nameerror-name-is-not-defined/m-p/1326023#M68858</link>
      <description>&lt;P&gt;I'd love to just load the entire script into my debugger here and run it, can you post the whole thing? Obviously redact private information if you need to.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 17:29:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/nameerror-name-is-not-defined/m-p/1326023#M68858</guid>
      <dc:creator>Brian_Wilson</dc:creator>
      <dc:date>2023-09-06T17:29:23Z</dc:date>
    </item>
  </channel>
</rss>

