<?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: Max Date - How to return unique IDs with Max Date in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30519#M2415</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This ***untested*** code should give you a list of the unique Ids (I assume you want to use the OBJECTID field), that represent the most recent test date for each occurance of HydrId. You could then load this list of OIDs (latestTestOidList in the code below) into a SQL query.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;hydrantDict = {}
searchRows = arcpy.da.SearchCursor(hydrantTable, ["OID@","TestDate","HydrID"])
for searchRow in searchRows:
&amp;nbsp;&amp;nbsp; oidValue, testDate, hydrantId = searchRow
&amp;nbsp;&amp;nbsp; if hydrantId not in hydrantDict:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hydrantDict[hydrantId] = [(testDate, oidValue)]
&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hydrantDict[hydrantId].append((testDate, oidValue))
del searchRow, searchRows
latestTestOidList = [sorted(dict[hydrantId], reverse=True)[0][1] for hydrantId in hydrantDict]&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 21:13:42 GMT</pubDate>
    <dc:creator>ChrisSnyder</dc:creator>
    <dc:date>2021-12-10T21:13:42Z</dc:date>
    <item>
      <title>List Broken Data Source's Path</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30502#M2398</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi everyone, I'm a very amateur Python user. I've managed to get the following, which I pieced together from here and there, working for the most part. I need to create a csv file which has a column showing the path to the data source which is broken. Everything works fine and dandy if I take out the dataSource part; when I add it in, it will run for a while and then fail. It seems to be getting tripped up on some mxd or data source it doesn't like perhaps? I have no clue. Here's my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy, os
path = r"H:\Plans\GIS Plans\2003"
f = open('BrokenMXD2003.csv', 'w')
f.write("Type, File Path, Layer, Broken Path" + "\n")
for root, dirs, files in os.walk(path):
&amp;nbsp;&amp;nbsp;&amp;nbsp; for fileName in files:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; basename, extension = os.path.splitext(fileName)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if extension == ".mxd":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fullPath = os.path.join(root, fileName)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(fullPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brknMXD = arcpy.mapping.ListBrokenDataSources(mxd)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for brknItem in brknMXD:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrList = arcpy.mapping.ListLayers(mxd)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.write("MXD, " + fullPath + ", " + brknItem.name)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if brknItem.supports("dataSource"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.write(", " + brknItem.dataSource + "\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.write("\n")

f.close()

print "Script Completed"&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And here's the error I get:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "X:\Documents\Working Files\Broken Data Sources\ListBrokenMXD.py", line 11, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; brknMXD = arcpy.mapping.ListBrokenDataSources(mxd)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "D:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\utils.py", line 181, in fn_&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return fn(*args, **kw)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "D:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\mapping.py", line 1465, in ListBrokenDataSources&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = mixins.MapDocumentMixin(map_document_or_layer).listBrokenDataSources()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "D:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\arcobjects\mixins.py", line 832, in listBrokenDataSources&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; broken_sources = [l for l in self.layers if not l._arc_object.valid]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "D:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\arcobjects\mixins.py", line 683, in layers&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for frame in reversed(self.dataFrames):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "D:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\arcobjects\mixins.py", line 695, in dataFrames&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return map(convertArcObjectToPythonObject, self.pageLayout.dataFrames)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AttributeError: 'NoneType' object has no attribute 'dataFrames'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It does run and create several lines of output, but this error appears when it gets near to the end of the mxd's in the directory. I haven't a clue what the problem could be, as I said I'm quite amateur. If anyone can see what it is, I'd be greatly appreciative. Thank you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Aug 2013 16:49:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30502#M2398</guid>
      <dc:creator>LauraMiles1</dc:creator>
      <dc:date>2013-08-07T16:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: List Broken Data Source's Path</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30503#M2399</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Instead of populating an excel spreadsheet this will show the results in IDLE:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy, os

path = r"C:\Test"

for root, dirs, files in os.walk(path):
&amp;nbsp;&amp;nbsp;&amp;nbsp; for fileName in files:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; basename, extension = os.path.splitext(fileName)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if extension == ".mxd":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fullPath = os.path.join(root, fileName)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(fullPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brknMXD = arcpy.mapping.ListBrokenDataSources(mxd)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for brknItem in brknMXD:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "MXD: " +fileName
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if brknItem.supports("workspacePath"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; source = brknItem.workspacePath
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print&amp;nbsp; str(brknItem) + ": " +&amp;nbsp; source
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Layer does not support source"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
print "Completed"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:13:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30503#M2399</guid>
      <dc:creator>LaurenYee</dc:creator>
      <dc:date>2021-12-10T21:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: List Broken Data Source's Path</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30504#M2400</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; &lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;File "X:\Documents\Working Files\Broken Data Sources\ListBrokenMXD.py", line 11, in &amp;lt;module&amp;gt;&lt;BR /&gt;brknMXD = arcpy.mapping.ListBrokenDataSources(mxd)&lt;/SPAN&gt; &lt;BR /&gt;File "D:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\utils.py", line 181, in fn_&amp;nbsp; &lt;BR /&gt;return fn(*args, **kw)&amp;nbsp; &lt;BR /&gt;File "D:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\mapping.py", line 1465, in ListBrokenDataSources&amp;nbsp; &lt;BR /&gt;result = mixins.MapDocumentMixin(map_document_or_layer).listBrokenDataSources()&amp;nbsp; &lt;BR /&gt;File "D:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\arcobjects\mixins.py", line 832, in listBrokenDataSources&amp;nbsp; &lt;BR /&gt;broken_sources = [l for l in self.layers if not l._arc_object.valid]&amp;nbsp; &lt;BR /&gt;File "D:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\arcobjects\mixins.py", line 683, in layers&amp;nbsp; &lt;BR /&gt;for frame in reversed(self.dataFrames):&amp;nbsp; &lt;BR /&gt; &lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;File "D:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\arcobjects\mixins.py", line 695, in dataFrames&lt;BR /&gt;return map(convertArcObjectToPythonObject, self.pageLayout.dataFrames)&lt;BR /&gt;AttributeError: 'NoneType' object has no attribute 'dataFrames'&lt;/SPAN&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The traceback (error report) is indicating that the problem is within the Arcpy libraries, but is caused by line 11 of your script, &lt;/SPAN&gt;&lt;STRONG style="font-style: italic;"&gt;brknMXD = arcpy.mapping.ListBrokenDataSources(mxd)&lt;/STRONG&gt;&lt;SPAN&gt;. I would guess that at some point you are passing an invalid mxd path...?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try printing the mxd path each time (change is shown in red):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
path = r"H:\Plans\GIS Plans\2003"
f = open('BrokenMXD2003.csv', 'w')
f.write("Type, File Path, Layer, Broken Path" + "\n")
for root, dirs, files in os.walk(path):
&amp;nbsp;&amp;nbsp;&amp;nbsp; for fileName in files:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; basename, extension = os.path.splitext(fileName)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if extension == ".mxd":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fullPath = os.path.join(root, fileName)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(fullPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG style="color: &amp;quot;#FF0000&amp;quot;;"&gt;arcpy.AddMessage(mxd)&lt;/STRONG&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brknMXD = arcpy.mapping.ListBrokenDataSources(mxd)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for brknItem in brknMXD:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrList = arcpy.mapping.ListLayers(mxd)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.write("MXD, " + fullPath + ", " + brknItem.name)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if brknItem.supports("dataSource"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.write(", " + brknItem.dataSource + "\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.write("\n")

f.close()

print "Script Completed"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:13:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30504#M2400</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2021-12-10T21:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: List Broken Data Source's Path</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30505#M2401</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Lauren, thanks for your answer. I'm actually successful at creating and populating the csv file, it just hangs up near the end of cycling through all the mxd's and doesn't finish the job. It puts out a csv file just fine, with the majority of the broken links listed, it just doesn't make it through every mxd in the folder and I'm not sure what the error I'm being given means.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I notice you used "workspacePath" rather than "dataSource". I tested out your code in IDLE and it seems to be providing the same information as dataSource. I changed dataSource to workspacePath in my code and tested that out. Both using your code as a straight copy and paste into IDLE, and changing dataSource to workspacePath in my own code, I'm getting the exact same error as I have been. Oddly, it does NOT stop at the same .mxd in both scenarios.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any clues out there???&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Aug 2013 21:02:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30505#M2401</guid>
      <dc:creator>LauraMiles1</dc:creator>
      <dc:date>2013-08-07T21:02:44Z</dc:date>
    </item>
    <item>
      <title>Re: List Broken Data Source's Path</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30506#M2402</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Stacy, I added this one line but it seems to have had no effect. I'm not familiar with addMessage; should there have been a popup or something? You mentioned printing the mxd path but I don't see where the results of addMessage should be added to my csv file or printed in IDLE?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've checked the .mxd's that aren't getting looped through; they open fine and seem to be "valid" so far as I can tell.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Aug 2013 21:22:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30506#M2402</guid>
      <dc:creator>LauraMiles1</dc:creator>
      <dc:date>2013-08-07T21:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: List Broken Data Source's Path</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30507#M2403</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi Stacy, I added this one line but it seems to have had no effect. I'm not familiar with addMessage; should there have been a popup or something? You mentioned printing the mxd path but I don't see where the results of addMessage should be added to my csv file or printed in IDLE?&lt;BR /&gt;&lt;BR /&gt;I've checked the .mxd's that aren't getting looped through; they open fine and seem to be "valid" so far as I can tell.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hey. This is kind of a long answer; first part attempts answer your questions, second part provides some general advice about what I think you could do to work out the problem and (hopefully) fix it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;AddMessage is kind of like print, except it will also work if you are running your code as a script tool within ArcMap (it will print to the little progress window). In your case it should simply print to the console output in IDLE, just like &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;print "Script Completed"&lt;/SPAN&gt;&lt;SPAN&gt; does. If AddMessage is not working, you could try just making that line &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;print mxd&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I didn't do a great job of describing what this will do, sorry. Having the print (or AddMessage) statement just before the crash will let you check which mxd is causing the crash. So your code will run, it will print each mxd that it analyses, then it will crash. The last mxd listed before the crash is the one potentially causing the problem. Then you can open it in ArcMap and do some other investigation on that particular file...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My guess is still that at some point this statement &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;mxd = arcpy.mapping.MapDocument(fullPath)&lt;/SPAN&gt;&lt;SPAN&gt; is returning something bad, and this is causing the next functional statement (&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;arcpy.mapping.ListBrokenDataSources(mxd)&lt;/SPAN&gt;&lt;SPAN&gt;) to fail.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Lauren's answer doesn't change anything from before the crash (apart from setting up the CSV), so it is interesting that it causes a crash on a different mxd. Does your original code &lt;/SPAN&gt;&lt;STRONG&gt;always &lt;/STRONG&gt;&lt;SPAN&gt;crash at the same place?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In a situation like this I would always recommend doing the simplest possible thing first, then isolate and fix any errors, then add more complexity once it works. For all we know the crash could be due to some strange conflict between Arc and the open file object (f), but to find this out we need to clearly build the code up step by step. So, perhaps just print to screen for now, get rid of everything related to the CSV&amp;nbsp; and everything after your crash:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
path = r"H:\Plans\GIS Plans\2003"
for root, dirs, files in os.walk(path):
&amp;nbsp;&amp;nbsp;&amp;nbsp; for fileName in files:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; basename, extension = os.path.splitext(fileName)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if extension == ".mxd":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fullPath = os.path.join(root, fileName)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(fullPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print mxd
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brknMXD = arcpy.mapping.ListBrokenDataSources(mxd)

print "Script Completed"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This should cause the crash, and the last printed mxd name should show the mxd causing the error. Once this is resolved, add the next layer of complexity, printing to the screen:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
path = r"H:\Plans\GIS Plans\2003"
for root, dirs, files in os.walk(path):
&amp;nbsp;&amp;nbsp;&amp;nbsp; for fileName in files:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; basename, extension = os.path.splitext(fileName)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if extension == ".mxd":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fullPath = os.path.join(root, fileName)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(fullPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print mxd
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brknMXD = arcpy.mapping.ListBrokenDataSources(mxd)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for brknItem in brknMXD:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print brknItem.name

print "Script Completed"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You will want to make sure that you have some mxds in your test set that you have designed with broken data sources, to ensure your code works for those.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If this runs OK, add the dataSource or workspacePath check (I don't know what either of these does, sorry...), printing them out. If everything checks out OK printing to screen, finally add the CSV output.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also noticed that this line in your original post doesn't do anything &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;lyrList = arcpy.mapping.ListLayers(mxd)&lt;/SPAN&gt;&lt;SPAN&gt;; I would recommend removing it if unused, at best it will slow things down, but may cause other problems too.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:13:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30507#M2403</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2021-12-10T21:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: List Broken Data Source's Path</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30508#M2404</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi Lauren, thanks for your answer. I'm actually successful at creating and populating the csv file, it just hangs up near the end of cycling through all the mxd's and doesn't finish the job. It puts out a csv file just fine, with the majority of the broken links listed, it just doesn't make it through every mxd in the folder and I'm not sure what the error I'm being given means.&lt;BR /&gt;&lt;BR /&gt;I notice you used "workspacePath" rather than "dataSource". I tested out your code in IDLE and it seems to be providing the same information as dataSource. I changed dataSource to workspacePath in my code and tested that out. Both using your code as a straight copy and paste into IDLE, and changing dataSource to workspacePath in my own code, I'm getting the exact same error as I have been. Oddly, it does NOT stop at the same .mxd in both scenarios.&lt;BR /&gt;&lt;BR /&gt;Any clues out there???&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, in my code where I check datasources I've had more success using workspacePath... I wish I could tell you WHY that was, I'll try and find a resource. I think it may have been because most of the paths I needed to replace referenced SDE databases(?)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyway, I would follow the advice on this thread and start with a smaller script to cycle through your mxds and see which one is the culprit.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How many mxds are you cycling through? - also will you be replacing these datasources with something new?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Edit, I believe this is why I used workspacePath &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s30000004p000000.htm"&gt;instead &lt;/A&gt;&lt;SPAN&gt;. If you were to replace one path for another, it is easier to use workspacePath!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Aug 2013 12:21:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30508#M2404</guid>
      <dc:creator>LaurenYee</dc:creator>
      <dc:date>2013-08-08T12:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: List Broken Data Source's Path</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30509#M2405</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Stacy, thanks for your detailed response. Something very odd is happening indeed, because I noticed after I get the error message and the script seems to be just hanging there (tried waiting 1/2 an hour and saw no additions to my csv file), I close the script and after I've closed it there are several more .mxd's that appear in the csv file. I'm wondering if that's the reason it's not "stopping" on the same .mxd every time - it looks to me like it's crashed, but it's actually still running? I'm going to try running it overnight and see what's there in the morning.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I had the script running with no errors before adding in the dataSource or workspacePath. It's definitely something about that which is causing problems. I'll go through and simplify again, as per your suggestions, and see if I can narrow it down to any particular .mxd. The addMessage didn't print anything to the idle window. I also noticed I had that unused lyr line in there - forgot to remove that.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Some data types (ie. annotation feature classes) won't return a dataSource, and apparently an error will be thrown if you don't test them out first.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Lauren, thanks for the tip on workspacePath - I'll stick with this then. Eventually I want to repair the broken links, I'm trying to find out what/where they are first so I can figure out the paths to where the data has moved to. Our folder system was totally reorganized a few years back and I want to archive all these old .mxd's by creating map packages. Do you know if workspacePath is also better to use on layer files than dataSource? I have pretty much the same script which runs on all the layer files in a directory, not getting any errors with that one.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;UPDATE: I managed to isolate an .mxd, and when I checked into it, there was no data in it. No layers, just an empty data frame. This doesn't explain why sometimes the script would go past this point, or stop several .mxd's before this point? One time it even ran through every .mxd in the directory, though it still showed the error. Anyway I've deleted the offending .mxd and will try and find a way to identify an .mxd with no layers in it. I'd like to print this to my csv file as well. Thanks all for your help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Aug 2013 13:57:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30509#M2405</guid>
      <dc:creator>LauraMiles1</dc:creator>
      <dc:date>2013-08-08T13:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: Max Date - How to return unique IDs with Max Date</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30510#M2406</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Python Beginner - Using version 10.1 and not an SDE install I have an atribute table with firehydrant inspection data. I am trying to create a layer that will only show the records grouped by fire hydrant number and then only display the most recent inspection date. When I execute the following code it runs fine and does in fact create the layer but it doesn't select the Max Date. If I have a record for Hydrant 100 with two dates I only want the most recent date to be created within the new layer.&lt;BR /&gt;Appreciate any assistance on this.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env
env.workspace=r"Z:\GIS_Data\gdb\GIS_Test.gdb"

fc="COA_FH_Inspections"
cursor = arcpy.UpdateCursor(fc)
idlist = []
datelist = []

for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; idlist.append(row.getValue('HydrID'))
&amp;nbsp;&amp;nbsp;&amp;nbsp; datelist.append(row.getValue('TestDate'))
&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)

print idlist
print datelist

idunique = set(idlist)

#Make a layer from the feature class
arcpy.MakeFeatureLayer_management(fc, "lyr")

for i in idunique:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if i == idlist:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("lyr", "New_Selection", '"HydrID" = i')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("lyr", "subset_Selection",'"TestDate" = (Select Max("TestDate") from "lyr"')&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Again thank you - Terry&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SDE and personal geodatabases supposedly support subqueries, but they are not well documented and not easy to troubleshoot.&amp;nbsp; The Subquery has to return a single result and be in the format:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;RelateField2 IN (SELECT RelateField1 FROM Table1 WHERE SQLWhereClause1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also do not think a subquery for a Max value can come from the same table that you are making a selection on (at least I know they fail for an fgdb, but those are much more limited than SDE subqueries, so that may not be a restriction for your SDE database)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To do this I use the Summary Statistics.&amp;nbsp; Unfortunately dates do not allow you to perform summary functions in any ESRI tools.&amp;nbsp; The work around steps I have had to use are listed &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/89570-Select-By-Attributes-latest-date-from-Data-Table?highlight=max+date" rel="nofollow noopener noreferrer" target="_blank"&gt;here&lt;/A&gt;&lt;SPAN&gt;.&amp;nbsp; The advantage of the Summary Statistics approach over the approach you are attempting is that it can summarize thousands of max dates for thousands of unique IDs in under 2 minutes and do the selection of every Max date for every unique ID in the entire tables in one selection operation.&amp;nbsp; A Feature Class to Feature Class output of that selection can make a 1:1 joinable table for other summary or data transfer operations.&amp;nbsp; You can make the summary outputs to in memory tables if you don't want them written to disk.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Processing each ID with individual queries can take up to 100 times longer to process, since that causes a new disk read from the start of the table for each new query.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:13:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30510#M2406</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-10T21:13:34Z</dc:date>
    </item>
    <item>
      <title>Re: Max Date - How to return unique IDs with Max Date</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30511#M2407</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Perhaps I did not express myself clearly - I do not have SDE. I am dealing with a file gdb. When I export the table to Access then I can easily extract what I want but within Arc and python I am totally lost.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Aug 2013 16:04:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30511#M2407</guid>
      <dc:creator>TerryHiggins1</dc:creator>
      <dc:date>2013-08-08T16:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: Max Date - How to return unique IDs with Max Date</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30512#M2408</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Perhaps I did not express myself clearly - I do not have SDE. I am dealing with a file gdb. When I export the table to Access then I can easily extract what I want but within Arc and python I am totally lost.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Your screwed.&amp;nbsp; fgdb's support an extremely limited set of subqueries that are under the restrictions I mentioned and cannot do what you can do with personal geodatabases and SDE databases, which support full subquery functionality.&amp;nbsp; Fgdb subqueries can only return one value from an entire table and the table providing the subquery value (MAX, SUM, MEAN, etc) must be external to the table where you are making the selection based on the subquery value.&amp;nbsp; Nothing can make the approach your code is attempting work with an fgdb.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Aug 2013 16:09:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30512#M2408</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2013-08-08T16:09:28Z</dc:date>
    </item>
    <item>
      <title>Re: Max Date - How to return unique IDs with Max Date</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30513#M2409</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the response - obviously that was not what I wanted to here.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Aug 2013 16:15:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30513#M2409</guid>
      <dc:creator>TerryHiggins1</dc:creator>
      <dc:date>2013-08-08T16:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: Max Date - How to return unique IDs with Max Date</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30514#M2410</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I saw your post earlier and was attempting some possible approaches.&amp;nbsp; I thought about using NumPy to arrive at the max() statistic you are interested in, and it looked promising.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.da.FeatureClassToNumPyArray&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, it doesn't allow for Date fields!&amp;nbsp; arrggghhh!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;j&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Aug 2013 16:39:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30514#M2410</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2013-08-08T16:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: Max Date - How to return unique IDs with Max Date</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30515#M2411</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thanks for the response - obviously that was not what I wanted to here.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I know.&amp;nbsp; I have posted an Idea on the ideas page related to the &lt;/SPAN&gt;&lt;A href="https://c.na9.visual.force.com/apex/ideaList?c=09a300000004xET&amp;amp;sort=recent"&gt;poor handling and inconsistencies of date related summaries and operations in ArcMap here&lt;/A&gt;&lt;SPAN&gt; and requested that they improve the ability to get such information.&amp;nbsp; Please vote for it and offer any other comments or suggestions on that idea.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Aug 2013 16:43:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30515#M2411</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2013-08-08T16:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: Max Date - How to return unique IDs with Max Date</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30516#M2412</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Are you opposed or comfortable using a different library?&amp;nbsp; You can EASILY acheive what you want with Pandas:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

import arcpy
from pandas import *

ws = "H:\Documents\ArcGIS\Default.gdb"
arcpy.env.workspace = ws
fc = "MyFC"
fields = ["_currentvalue", "_pastvalue", "_curDate"]
array = []

for field in fields:
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(fc, fields) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array.append(row)

df = DataFrame(array, columns = ["_currentvalue", "_pastvalue", "_curDate"])

maxDate = df._curDate.max()

print maxDate&amp;nbsp; #&amp;lt;--- this gives me the correct max date 

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have found many other uses for the pandas library too -- very powerful and a welcomed addition to my codebase!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Good luck,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;james&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:13:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30516#M2412</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-10T21:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: Max Date - How to return unique IDs with Max Date</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30517#M2413</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;A href="http://forums.arcgis.com/threads/89883-Are-complex-SQL-queries-supported-in-ArcObjects?highlight=subqueries"&gt;Here is another post&lt;/A&gt;&lt;SPAN&gt; discussing the limitations of subqueries when using fgdb's.&amp;nbsp; The Pandas approach is probably your best option within Python as a work around.&amp;nbsp; I personally want better support in the basic geoprocessing tools for finding Min and Max dates.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Aug 2013 17:00:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30517#M2413</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2013-08-08T17:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: Max Date - How to return unique IDs with Max Date</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30518#M2414</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How about using a dictionary&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env
env.workspace=r"Z:\GIS_Data\gdb\GIS_Test.gdb"

fc="COA_FH_Inspections"
cursor = arcpy.SearchCursor(fc) #Update cursor is for updating the data in the fc's row, search cursor should suffice in this situation
idlist = []

for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; idlist.append(row.getValue('HydrID'))

print idlist

idunique = set(idlist)

###MY ADDITIONAL CODE###

#create dictionary with structure {&amp;lt;hydrantID&amp;gt;:(&amp;lt;objectid&amp;gt;,&amp;lt;Date&amp;gt;),...}
maxDates = {}
for item in idunique:
&amp;nbsp;&amp;nbsp;&amp;nbsp; maxDates[item] = (0,"1/1/1900")

features = arcpy.SearchCursor(fc)

for feature in features:
&amp;nbsp;&amp;nbsp;&amp;nbsp; hydrant = feature.getValue('HydrID')
&amp;nbsp;&amp;nbsp;&amp;nbsp; testDate = feature.getValue('TestDate')
&amp;nbsp;&amp;nbsp;&amp;nbsp; objectID = feature.getValue('objectid')
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; if testDate &amp;gt; maxDates[hydrant][1]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; maxDates[hydrant] = (objectID, testDate) #if the date is greater, replace the (&amp;lt;objectid&amp;gt;,&amp;lt;date&amp;gt;) tuple with new values

#maxDates can now be used to collect the features
#for illustration purposes:
keepers = []
for key in maxDates:
&amp;nbsp;&amp;nbsp;&amp;nbsp; hydrant = key
&amp;nbsp;&amp;nbsp;&amp;nbsp; objectID = key[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Hydrant {0} with ObjectID {1} has the most recent inspection date".format(hydrant,objectID)
&amp;nbsp;&amp;nbsp;&amp;nbsp; keepers.append(objectID)

#Use keepers to identify the rows in the feature class and write them out to a new feature class

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Almost certainly will need additional tweaks, but that's the concept.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:13:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30518#M2414</guid>
      <dc:creator>MattSayler</dc:creator>
      <dc:date>2021-12-10T21:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: Max Date - How to return unique IDs with Max Date</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30519#M2415</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This ***untested*** code should give you a list of the unique Ids (I assume you want to use the OBJECTID field), that represent the most recent test date for each occurance of HydrId. You could then load this list of OIDs (latestTestOidList in the code below) into a SQL query.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;hydrantDict = {}
searchRows = arcpy.da.SearchCursor(hydrantTable, ["OID@","TestDate","HydrID"])
for searchRow in searchRows:
&amp;nbsp;&amp;nbsp; oidValue, testDate, hydrantId = searchRow
&amp;nbsp;&amp;nbsp; if hydrantId not in hydrantDict:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hydrantDict[hydrantId] = [(testDate, oidValue)]
&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hydrantDict[hydrantId].append((testDate, oidValue))
del searchRow, searchRows
latestTestOidList = [sorted(dict[hydrantId], reverse=True)[0][1] for hydrantId in hydrantDict]&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:13:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30519#M2415</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-10T21:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: Max Date - How to return unique IDs with Max Date</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30520#M2416</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; Your screwed. fgdb's support an extremely limited set of subqueries that are under the restrictions I mentioned and cannot do what you can do with personal geodatabases and SDE databases, which support full subquery functionality. Fgdb subqueries can only return one value from an entire table and&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:&amp;quot;#0000FF&amp;quot;;"&gt;the table providing the subquery value (MAX, SUM, MEAN, etc) must be external to the table where you are making the selection&lt;/SPAN&gt; based on the subquery value. Nothing can make the approach your code is attempting work with an fgdb.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is not correct. A scalar sub-query in FileGDB can reference the same table. I do this all the time, and it was written specifically for this purpose. For example, if my table is ROADS, I can execute the following sub-query in a WHERE clause:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; OID = (SELECT MAX(OID) FROM ROADS)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Could you provide some specific examples of the things you have tried that do not work as you would like?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Aug 2013 18:03:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30520#M2416</guid>
      <dc:creator>DavidSousa</dc:creator>
      <dc:date>2013-08-08T18:03:27Z</dc:date>
    </item>
    <item>
      <title>Re: Max Date - How to return unique IDs with Max Date</title>
      <link>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30521#M2417</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;This is not correct.&amp;nbsp; A scalar sub-query in FileGDB can reference the same table.&amp;nbsp; I do this all the time, and it was written specifically for this purpose.&amp;nbsp; For example, if my table is ROADS, I can execute the following sub-query in a WHERE clause:&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; OID = (SELECT MAX(OID) FROM ROADS)&lt;BR /&gt;&lt;BR /&gt;Could you provide some specific examples of the things you have tried that do not work as you would like?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;David:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for correcting me and weighing in on this subject.&amp;nbsp; Apparently my problems in attempting subqueries are either than my information is out of date (derived from tests mostly done at 9.3) or that this is related to the poor documentation that confuses syntax from many databases in the SQL Reference, which is what I have always tried to follow.&amp;nbsp; In any case, I can confirm that after following David's examples he provided me in an e-mail that an fgdb can make subquery selections as David has said.&amp;nbsp; Also fgdb subqueries can return Max(Date) values.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The subquery can operate within a selection involving a single table and they can select based on Max date.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So in reality it appears that the problem is that you cannot use "lyr" as the table name in the subquery.&amp;nbsp; You must use the underlying Feature Class name.&amp;nbsp; So for example, if my layer is named CENTERLINE but the underlying feature class of the layer is named CENTERLINE_EXTENDED, this subquery will not work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"MODIFIED_DATE" = (SELECT MAX("MODIFIED_DATE") FROM CENTERLINE WHERE "STNAME" = 'HIGH VISTA DR')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;but it will work if I put the actual feature class name.&amp;nbsp; So this does work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"MODIFIED_DATE" = (SELECT MAX("MODIFIED_DATE") FROM CENTERLINE_EXTENDED WHERE "STNAME" = 'HIGH VISTA DR')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So you do not need two queries, just one for your problem.&amp;nbsp; However, you need to use the underlying name of the fc variable.&amp;nbsp; So something like this should replace the two queries in the original post (untested and not sure if I have to access a property of the fc to get its name):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management("lyr", "subset_Selection",'"HydrID" = ' + i + ' And "TestDate" = (Select Max("TestDate") from ' + fc + ' WHERE "HydrID" = ' + i)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Aug 2013 18:25:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-broken-data-source-s-path/m-p/30521#M2417</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2013-08-08T18:25:32Z</dc:date>
    </item>
  </channel>
</rss>

