AnsweredAssumed Answered

Change output filename by adding a text in Python

Question asked by dljayasekera on Nov 27, 2017
Latest reply on Nov 27, 2017 by dljayasekera

HI,

 

I need to add "_var86" to the output file in the code below. How can I achieve it in the code below. 

 

Thanks in advance.

import arcpy, sys 
from arcpy import env
from arcpy.sa import *

# Input data source
arcpy.env.workspace = r"C:/Users/Desktop/weekly_avg_project"
arcpy.env.overwriteOutput = True

# Set output folder
OutputFolder = r"C:/Users/Desktop/weekly_avg_project/output"

# Loop through a list of files in the workspace
NCfiles = arcpy.ListFiles("*.nc")

for filename in NCfiles:
print("Processing: " + filename)
inNCfiles = arcpy.env.workspace + "//" + filename
fileroot = filename[0:(len(filename)-3)]
TempLayerFile = "SM_amount"
outRaster = OutputFolder + "//" + fileroot
# Process: Make NetCDF Raster Layer
outfile = arcpy.MakeNetCDFRasterLayer_md(filename, "var86", "lon", "lat", TempLayerFile, "", "", "BY_VALUE")
proj_ras = arcpy.ProjectRaster_management(outfile, "C:/Users/Desktop/weekly_avg_project/project_ras","GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]", "NEAREST", "0.125 0.125", "NAD_1983_To_WGS_1984_1", "", "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]")
# Process: Copy Raster
arcpy.CopyRaster_management(proj_ras, outRaster + ".tif", "", "", "", "NONE", "NONE", "")

Outcomes