Select to view content in your preferred language

Creating a text file on python

2203
5
07-20-2012 03:20 PM
ZulyG
by
Emerging Contributor
[PHP][/PHP]

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:

<type 'exceptions.IOError'>: [Errno 13] Permission denied: 'draft'
Failed to execute (Script).

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.

Any ideas?
Tags (2)
0 Kudos
5 Replies
DanPatterson_Retired
MVP Emeritus
do you have line in your script that says
arcpy.overWriteOutputs = 1
and if you open the output from the first run you won't be able to overwrite it in any event
0 Kudos
ZulyG
by
Emerging Contributor

[/HR]


I don't have a line in my script that says "arcpy.overWriteOutputs = 1"
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.
But I only get the error when I open open ArcMap/ArcCatalog for the first time.
0 Kudos
VikramS
Frequent Contributor
Do you check if the file already exists before calling the delete function

check like below

import os
if os.exists(Full path of the text file"):
       os.delete(Full path of the text file)
0 Kudos
ChrisBater
Deactivated User
Try something like this.....

import os

draftFileName = r'd:\temp\draft.txt'
draftFile = open(draftFileName, 'w')
#do stuff
draftFile.close()
if os.path.exists(draftFileName):
    os.remove(draftFileName)
0 Kudos
ZulyG
by
Emerging Contributor
Do you check if the file already exists before calling the delete function

check like below

import os
if os.exists(Full path of the text file"):
       os.delete(Full path of the text file)


I do have a file that checks if the file already exists ..and it comes out false
0 Kudos