1

I have a python script running from ArcToolbox. Each time the script is run, it creates a new text file (testtext.txt), writes to it, then deletes it at the end.

Before the script is re-pointed, the source looks like this: enter image description here

When I try to run the tool, I get the error: enter image description here

If I go into the properties of the script and re-point the source to the exact same location as shown above, the script does work, and works fine every time thereafter. This problem happens when logged in as Administrator on the computer as well. Is there a way to ensure permission without having to re-point the source each time the tool is added to ArcMap?

I have "Store relative path names" enabled on the script properties. Here is the code snippet:

tempPath = sys.path[0]
newPath = os.path.join("testtext.txt")

open(newPath, 'w').close()
with open(newPath,"a") as newfile:
    newfile.write("http://genericaddress/#/selections/place?query=")
outfile = open(newPath,"a")

1 Answer 1

2

I believe the issue is with your variable newPath. You will need to designate a directory as well as the name of the text file for the script to work.

Try something like this to set the variable:

newPath = os.path.join (r"C:\test", "testtext.txt")

I can't say how the script works without it. I hope this helps!

2
  • thank you. Is this a viable option if I want to share this tool? I don't necessarily want to force them to write to a certain drive. That's why I thought writing the script to wherever they save the file to would work.
    – Steven C
    Dec 12, 2014 at 22:38
  • 2
    Sure. Any string can be assigned to a variable. Assign the input to a variable, such as PATH, and then the code would be newpath = os.path.join (PATH, "testtext.txt"). You will probably need to use arcpy.GetParameterAsText to set the varaible PATH and allow for users to input it. Dec 12, 2014 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.