<?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: A way to loop through print outputs and write them to a file? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/a-way-to-loop-through-print-outputs-and-write-them/m-p/709874#M55027</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm pretty sure this was just an indention error that I didn't see at first.&amp;nbsp; Code works now.&amp;nbsp; #oops&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 08 Jan 2015 19:05:10 GMT</pubDate>
    <dc:creator>JasonDowdy</dc:creator>
    <dc:date>2015-01-08T19:05:10Z</dc:date>
    <item>
      <title>A way to loop through print outputs and write them to a file?</title>
      <link>https://community.esri.com/t5/python-questions/a-way-to-loop-through-print-outputs-and-write-them/m-p/709873#M55026</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have this code, same code I posted yesterday but different piece.&amp;nbsp; In 10.2.2 I am trying to get the script to write all print outputs to a text file.&amp;nbsp; Code block in question starts at line 18.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="python" name="code"&gt;import arcpy, os, sys&amp;nbsp; arcpy.env.workspace = arcpy.GetParameterAsText(0)&amp;nbsp; def get_size(start_path = arcpy.env.workspace): &amp;nbsp;&amp;nbsp;&amp;nbsp; total_size = 0 &amp;nbsp;&amp;nbsp;&amp;nbsp; for dirpath, dirnames, filenames in os.walk(start_path): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for f in filenames: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fp = os.path.join(dirpath, f) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; total_size += os.path.getsize(fp) &amp;nbsp;&amp;nbsp;&amp;nbsp; return round((total_size / float(1048576)), 2) print "Total Size before Compact " + str(get_size()) + "mb" results = open("R:\\results.txt","w") results.write("Total Size before Compact " + str(get_size()) + "mb" + '\n')&amp;nbsp; feature_classes = []&amp;nbsp; for dirpath, dirnames, filenames in arcpy.da.Walk(arcpy.env.workspace, datatype="Container"): &amp;nbsp;&amp;nbsp;&amp;nbsp; for dirname in dirnames: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ".gdb" in dirname: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Compact_management(os.path.join(dirpath, dirname)) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Successfully compacted " + dirname results.write("Successfully compacted " + dirname + '\n') results.close()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are hundreds of GDBs in this workspace.&amp;nbsp; In the ArcMap console, it returns each GDB it finds and prints "&lt;SPAN style="color: #909090;"&gt;Successfully compacted this.gdb&lt;/SPAN&gt;".&amp;nbsp; However, when I try to write the print to a file it only writes the last GDB in the list.&amp;nbsp; How do I get it to list every GDB it successfully compacts in the text file? Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 18:58:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/a-way-to-loop-through-print-outputs-and-write-them/m-p/709873#M55026</guid>
      <dc:creator>JasonDowdy</dc:creator>
      <dc:date>2015-01-08T18:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: A way to loop through print outputs and write them to a file?</title>
      <link>https://community.esri.com/t5/python-questions/a-way-to-loop-through-print-outputs-and-write-them/m-p/709874#M55027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm pretty sure this was just an indention error that I didn't see at first.&amp;nbsp; Code works now.&amp;nbsp; #oops&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 19:05:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/a-way-to-loop-through-print-outputs-and-write-them/m-p/709874#M55027</guid>
      <dc:creator>JasonDowdy</dc:creator>
      <dc:date>2015-01-08T19:05:10Z</dc:date>
    </item>
  </channel>
</rss>

