<?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: List comprehension with statement using arcpy.da cursors? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/list-comprehension-with-statement-using-arcpy-da/m-p/198262#M15207</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Jason... In the docs I saw the part about the with statement "guarantee close and release of database locks and reset iteration", and thought that sounded good, but as long as the cursor executes successfully I guess that does that anyway.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 13 Aug 2012 15:07:39 GMT</pubDate>
    <dc:creator>ChrisSnyder</dc:creator>
    <dc:date>2012-08-13T15:07:39Z</dc:date>
    <item>
      <title>List comprehension with statement using arcpy.da cursors?</title>
      <link>https://community.esri.com/t5/python-questions/list-comprehension-with-statement-using-arcpy-da/m-p/198260#M15205</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Excited to get my hands dirty using the arcpy.da module, and I appreciate the reasoning for the optional "with" statement syntax.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Question:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;While it is possible to do this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;tileList = [r[0] for r in arcpy.da.SearchCursor(freq1Tbl, "TILE_NO")]&lt;/PRE&gt;&lt;SPAN&gt;it doesn't seem possible to do this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;tileList = [row[0] for row in cursor with arcpy.da.SearchCursor(freq1Tbl, "TILE_NO") as cursor]&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Am I using the wrong syntax here, or can you just not use the with statement in a list/dictionary comprehension?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Aug 2012 17:29:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-comprehension-with-statement-using-arcpy-da/m-p/198260#M15205</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2012-08-10T17:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: List comprehension with statement using arcpy.da cursors?</title>
      <link>https://community.esri.com/t5/python-questions/list-comprehension-with-statement-using-arcpy-da/m-p/198261#M15206</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The with statement does not work in a list comprehension, no. There's no need for it assuming the comprehension does not throw an exception, though. Once a da cursor runs out of rows it closes itself in the same manner as it would leaving a with block.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Aug 2012 19:44:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-comprehension-with-statement-using-arcpy-da/m-p/198261#M15206</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2012-08-10T19:44:27Z</dc:date>
    </item>
    <item>
      <title>Re: List comprehension with statement using arcpy.da cursors?</title>
      <link>https://community.esri.com/t5/python-questions/list-comprehension-with-statement-using-arcpy-da/m-p/198262#M15207</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Jason... In the docs I saw the part about the with statement "guarantee close and release of database locks and reset iteration", and thought that sounded good, but as long as the cursor executes successfully I guess that does that anyway.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2012 15:07:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-comprehension-with-statement-using-arcpy-da/m-p/198262#M15207</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2012-08-13T15:07:39Z</dc:date>
    </item>
  </channel>
</rss>

