<?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: Creating a text file on python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/creating-a-text-file-on-python/m-p/585557#M45980</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try something like this.....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os

draftFileName = r'd:\temp\draft.txt'
draftFile = open(draftFileName, 'w')
#do stuff
draftFile.close()
if os.path.exists(draftFileName):
&amp;nbsp;&amp;nbsp;&amp;nbsp; os.remove(draftFileName)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 01:10:36 GMT</pubDate>
    <dc:creator>ChrisBater</dc:creator>
    <dc:date>2021-12-12T01:10:36Z</dc:date>
    <item>
      <title>Creating a text file on python</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-text-file-on-python/m-p/585553#M45976</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;[PHP][/PHP]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a toolbox where I have created a python script. I am trying to create a text file called draft where I am writting in some information. Every time I run my script I get the followign error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;type 'exceptions.IOError'&amp;gt;: [Errno 13] Permission denied: 'draft'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (Script).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, when I go to properties and and "re-set" the source, the script it works again, eventhough the previous source was the correct source. The script will then run fine until I close ArcMap and open it again. I get the same error and once I "re-set" the source it works again. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jul 2012 22:20:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-text-file-on-python/m-p/585553#M45976</guid>
      <dc:creator>ZulyG</dc:creator>
      <dc:date>2012-07-20T22:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a text file on python</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-text-file-on-python/m-p/585554#M45977</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;do you have line in your script that says&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.overWriteOutputs = 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and if you open the output from the first run you won't be able to overwrite it in any event&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jul 2012 22:54:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-text-file-on-python/m-p/585554#M45977</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2012-07-20T22:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a text file on python</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-text-file-on-python/m-p/585555#M45978</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;&lt;HR /&gt;[/HR]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't have a line in my script that says "arcpy.overWriteOutputs = 1"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am creating the text file so there is no previous file with that name. Every time I run it, at the end of the script I delete the file. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But I only get the error when I open open ArcMap/ArcCatalog for the first time.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Jul 2012 17:58:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-text-file-on-python/m-p/585555#M45978</guid>
      <dc:creator>ZulyG</dc:creator>
      <dc:date>2012-07-23T17:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a text file on python</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-text-file-on-python/m-p/585556#M45979</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Do you check if the file already exists before calling the delete function &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;check like below &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import os &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if os.exists(Full path of the text file"):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.delete(Full path of the text file)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jul 2012 14:08:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-text-file-on-python/m-p/585556#M45979</guid>
      <dc:creator>VikramS</dc:creator>
      <dc:date>2012-07-24T14:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a text file on python</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-text-file-on-python/m-p/585557#M45980</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try something like this.....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os

draftFileName = r'd:\temp\draft.txt'
draftFile = open(draftFileName, 'w')
#do stuff
draftFile.close()
if os.path.exists(draftFileName):
&amp;nbsp;&amp;nbsp;&amp;nbsp; os.remove(draftFileName)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:10:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-text-file-on-python/m-p/585557#M45980</guid>
      <dc:creator>ChrisBater</dc:creator>
      <dc:date>2021-12-12T01:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a text file on python</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-text-file-on-python/m-p/585558#M45981</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Do you check if the file already exists before calling the delete function &lt;BR /&gt;&lt;BR /&gt;check like below &lt;BR /&gt;&lt;BR /&gt;import os &lt;BR /&gt;if os.exists(Full path of the text file"):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.delete(Full path of the text file)&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I do have a file that checks if the file already exists ..and it comes out false&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jul 2012 23:24:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-text-file-on-python/m-p/585558#M45981</guid>
      <dc:creator>ZulyG</dc:creator>
      <dc:date>2012-07-25T23:24:58Z</dc:date>
    </item>
  </channel>
</rss>

