defining arcpy outputs and general practice

179
3
05-13-2021 09:42 AM
Df1soton
New Contributor

Hi 

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:

Df1soton_0-1620924050649.png

error message:

Df1soton_1-1620924158419.png

 

0 Kudos
3 Replies
JoeBorgione
MVP Esteemed Contributor

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.

can't wait to retire....
BlakeTerhune
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.

DanPatterson
MVP Honored Contributor

For future reference,

Code formatting ... the Community Version - Esri Community

would help with code readability, rather than screen grabs


... sort of retired...