Select to view content in your preferred language

defining arcpy outputs and general practice

05-13-2021 09:42 AM
New Contributor


I'm very new to python and i'm currently writing a script for one of my MSc Modules.

we have been given some ascii files that we need to convert to rasters, then define a projection and reproject them to british national grid. i'm currently having trouble with working out how to get python to output to specific folders and how to make the file names comply with tool parameters 

current code:


error message:



0 Kudos
3 Replies
MVP Emeritus

Its hard to read your screen captures; if you expand the three dots on the menu bar and choose the </> icon you can enter your text as python code to make it easier to read.  That said, you can set an environment parameter to overwrite existing features every time you run the script.

import arcpy
arcpy.env.overwriteOutput = True

This approach has a storied history of sometimes not working, so you can look at the arcpy exists method.

And if/when that doesn't work, you can pull out the big hammer and use python os.exists() method.

That should just about do it....
MVP Regular Contributor

You're not dynamically creating outpudata so it's trying to overwrite the same thing over and over. If that's not what you want, then you should be creating outpudata similarly to how you do in the loop before. Additionally, Outdir should not have that trailing underscore character when it's defined at the top unless you actually have a folder named "_".

Where you're adding the rasters to the conversion list, try just adding a string as a file path to the raster instead of an arcpy raster object.

MVP Esteemed Contributor

For future reference,

Code formatting ... the Community Version - Esri Community

would help with code readability, rather than screen grabs

... sort of retired...