<?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: Search Cursor in Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133831#M10454</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Chris-&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for the past (2) posts. I will look at both ideas and see what I can come up with. Guess I should have said I am working on ArcMap 10.2&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Also, instead of creating a list of each "TWACs_NUMBER", and running a seperate cursor for each one, just run a single cursor and store the lists in a dictionary, where each twacNo is a key and each key points to a list of meterNos. In v10.1 this would look like:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;twacDict = {}
searchRows = arcpy.da.SearchCursor(table, ["TWACs_NUMBER","METER_NUMBER"])
for searchRow in searchRows:
&amp;nbsp;&amp;nbsp; twacNo, meterNo = searchRow
&amp;nbsp;&amp;nbsp; if twacNo in twacDict:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; twacDict[twacNo].append(meterNo)
&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; twacDict[twacNo] = [meterNo]
del searchRow, searchRows

twackList = twacDict.keys()
twackList.sort()
for twacNo in twackList:
&amp;nbsp;&amp;nbsp; meterList = twacDict[twacNo]
&amp;nbsp;&amp;nbsp; #make a graph here, since you now have a hook to the twacNo and it's list of meterNos&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 07:29:41 GMT</pubDate>
    <dc:creator>ModernElectric</dc:creator>
    <dc:date>2021-12-11T07:29:41Z</dc:date>
    <item>
      <title>Search Cursor in Python</title>
      <link>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133822#M10445</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a Python script that starts with a Search Cursor that goes through a File Geodatabase and looks for a unique number and produces a graph and prints it out to a .PDF. The Script works out just fine. BUT - each time I run it - it seems to take longer and longer. The first few times - it produces about 4 .PDFs each minute. Now - when I run it - it goes slower and slower - about 1 .PDF every 2 minutes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does the Search Cursor produce "Temp" files somewhere that needs to be cleared out? How can I speed this up?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Sep 2013 16:26:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133822#M10445</guid>
      <dc:creator>ModernElectric</dc:creator>
      <dc:date>2013-09-25T16:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Search Cursor in Python</title>
      <link>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133823#M10446</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;What version of ArcGIS are you using? Can you post the code you are running? Search Cursors are quite light and shouldn't be creating any additional files. Are you sure it isn't some other part of your code that is causing the issue?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Sep 2013 16:40:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133823#M10446</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-09-25T16:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: Search Cursor in Python</title>
      <link>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133824#M10447</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Name: Electric Meter Demand Graphs - Usage.py
# Description: Python script to take a single TWACs Meter and create a Usage Graphs per Feeder
# Date Created: Tuesday, September 17th, 2013 @ 1:20 PM
# Date Modified: Tuesday, September 17th, 2013 @ 1:20 PM
# Author: C. Wafstet #94 - Modern Electric Water Company (Spokane, WA)

import arcpy
import arcpy
import logging
from arcpy import env
env.overwriteOutput = 1
env.workspace = r"C:\MEWCo GIS System\Electric System\MEWCo_Electric_Model-LOCAL.gdb"

table = "SERVICE_METERS_DEMAND_F1FEEDER_ABC"

list = []

# if run in ArcGIS Desktop, show messages, also print to log
def log(method, msg):
&amp;nbsp;&amp;nbsp;&amp;nbsp; print msg
&amp;nbsp;&amp;nbsp;&amp;nbsp; method(msg)

logging.basicConfig(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; level=logging.INFO,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format='%(asctime)s %(levelname)-s %(message)s',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datefmt='%a, %d %b %Y %H:%M:%S',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; filename='MakeGraph.log',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; filemode='w'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )

log(logging.info, "Creation of Graphs Started")

rows = arcpy.SearchCursor(table)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; list.append(row.TWACs_NUMBER)

del row, rows

# Remove duplicates from list
list = dict.fromkeys(list)
list = list.keys()

for n in list:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.TableSelect_analysis(table, r"in_memory\table_sel", "TWACs_NUMBER = " + str(n))

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get TWACs_Number value
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in arcpy.SearchCursor(r"in_memory\table_sel"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; METER_NUMBER = row.getValue("METER_NUMBER")

&amp;nbsp;&amp;nbsp;&amp;nbsp; out_graph_name = n
&amp;nbsp;&amp;nbsp;&amp;nbsp; out_graph_pdf = r"C:\MEWCo GIS System\Electric Graphs\Electric Meters\Usage Graphs\F-1 Feeder" + "\\" + str(n)[:-2] + "-Usage" + ".pdf"
&amp;nbsp;&amp;nbsp;&amp;nbsp; input_template = r"C:\MEWCo GIS System\Electric Graphs\GIS Graph Temps\ELECTRIC METER DEMAND - KWH USAGE.grf"
&amp;nbsp;&amp;nbsp;&amp;nbsp; input_data = r"in_memory\table_sel"

# Create the Graph
&amp;nbsp;&amp;nbsp;&amp;nbsp; graph = arcpy.Graph()

# Add a Vertical Bar series to the graph - KWH Usage
&amp;nbsp;&amp;nbsp;&amp;nbsp; graph.addSeriesBarVertical(input_data, "KWH_USAGE")

# Specify the title of the Left Axis
&amp;nbsp;&amp;nbsp;&amp;nbsp; graph.graphAxis[0].title = "KWH_USAGE"

# Specify the title of the Bottom Axis
&amp;nbsp;&amp;nbsp;&amp;nbsp; graph.graphAxis[2].title = "BILLING_PERIOD"

# Specify the title of the Graph
&amp;nbsp;&amp;nbsp;&amp;nbsp; graph.graphPropsGeneral.title = "KWH Usage by Electric TWACs Number: " + METER_NUMBER

# Output a graph, which is created in-memory
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeGraph_management(input_template, graph, out_graph_name)

# Save the graph as an .PDF
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SaveGraph_management(out_graph_name, out_graph_pdf, "MAINTAIN_ASPECT_RATIO", 600, 375)

log(logging.info, "Creation of Graphs Complete")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code works just fine.... I worked on it for awhile to make it work the way I want it too. It just seems like - each time I run it - it takes longer and longer.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:29:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133824#M10447</guid>
      <dc:creator>ModernElectric</dc:creator>
      <dc:date>2021-12-11T07:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Search Cursor in Python</title>
      <link>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133825#M10448</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I would find it more likely your log file is the issue. Try disabling logging and running it a few times to see if you get the same slow downs. Also, are you closing the instance of python this script is running in between executions? The in_memory workspace won't clear properly until you terminate the instance it was executed in or you clear it explicitly.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Sep 2013 16:58:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133825#M10448</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-09-25T16:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: Search Cursor in Python</title>
      <link>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133826#M10449</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I would find it more likely your log file is the issue. Try disabling logging and running it a few times to see if you get the same slow downs. Also, are you closing the instance of python this script is running in between executions? The in_memory workspace won't clear properly until you terminate the instance it was executed in or you clear it explicitly.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I will see what I does when I remove the logging from the script. Forgive me, but the second part you are talking about... what do you mean&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Sep 2013 17:01:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133826#M10449</guid>
      <dc:creator>ModernElectric</dc:creator>
      <dc:date>2013-09-25T17:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: Search Cursor in Python</title>
      <link>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133827#M10450</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This table "in_memory\table_sel" you create will persist until you close the instance it was created in.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Sep 2013 17:24:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133827#M10450</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-09-25T17:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: Search Cursor in Python</title>
      <link>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133828#M10451</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;This table "in_memory\table_sel" you create will persist until you close the instance it was created in.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;And how do I do that?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Sep 2013 17:36:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133828#M10451</guid>
      <dc:creator>ModernElectric</dc:creator>
      <dc:date>2013-09-25T17:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: Search Cursor in Python</title>
      <link>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133829#M10452</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure about the reason for the slow down, but some ideas to make it faster:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;OL&gt;&lt;BR /&gt;&lt;LI&gt;Just run the search cursor on the on-disk table directly. Copy the table to in_memory most likely is just adding overhead processing time.&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;In you are running v10.1+, use the data access cursors. They are about 20-30x faster than the old cursors you are using.&lt;/LI&gt;&lt;BR /&gt;&lt;/OL&gt;&lt;BR /&gt;&lt;SPAN&gt;Like Matt was saying, make sure you are restarting Python (or whatever .exe you are using) between runs of this script as to clear the RAM and remove locks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Sep 2013 20:18:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133829#M10452</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2013-09-25T20:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: Search Cursor in Python</title>
      <link>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133830#M10453</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Also, instead of creating a list of the"TWACs_NUMBERs", and running a seperate cursor for each one, just run a single cursor and store the lists in a dictionary, where each twacNo is a key and each key points to a list of meterNos. In v10.1 this would look like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;twacDict = {}
searchRows = arcpy.da.SearchCursor(table, ["TWACs_NUMBER","METER_NUMBER"])
for searchRow in searchRows:
&amp;nbsp;&amp;nbsp; twacNo, meterNo = searchRow
&amp;nbsp;&amp;nbsp; if twacNo in twacDict:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; twacDict[twacNo].append(meterNo)
&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; twacDict[twacNo] = [meterNo]
del searchRow, searchRows

twackList = twacDict.keys()
twackList.sort()
for twacNo in twackList:
&amp;nbsp;&amp;nbsp; meterList = twacDict[twacNo]
&amp;nbsp;&amp;nbsp; #make a graph here, since you now have a hook to the twacNo and it's list of meterNos&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:29:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133830#M10453</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T07:29:38Z</dc:date>
    </item>
    <item>
      <title>Re: Search Cursor in Python</title>
      <link>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133831#M10454</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Chris-&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for the past (2) posts. I will look at both ideas and see what I can come up with. Guess I should have said I am working on ArcMap 10.2&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Also, instead of creating a list of each "TWACs_NUMBER", and running a seperate cursor for each one, just run a single cursor and store the lists in a dictionary, where each twacNo is a key and each key points to a list of meterNos. In v10.1 this would look like:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;twacDict = {}
searchRows = arcpy.da.SearchCursor(table, ["TWACs_NUMBER","METER_NUMBER"])
for searchRow in searchRows:
&amp;nbsp;&amp;nbsp; twacNo, meterNo = searchRow
&amp;nbsp;&amp;nbsp; if twacNo in twacDict:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; twacDict[twacNo].append(meterNo)
&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; twacDict[twacNo] = [meterNo]
del searchRow, searchRows

twackList = twacDict.keys()
twackList.sort()
for twacNo in twackList:
&amp;nbsp;&amp;nbsp; meterList = twacDict[twacNo]
&amp;nbsp;&amp;nbsp; #make a graph here, since you now have a hook to the twacNo and it's list of meterNos&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:29:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-cursor-in-python/m-p/133831#M10454</guid>
      <dc:creator>ModernElectric</dc:creator>
      <dc:date>2021-12-11T07:29:41Z</dc:date>
    </item>
  </channel>
</rss>

