How to add a string to output filename if an optional arcpy.env.mask is used?

Discussion created by desc0107 on Jul 11, 2011
Latest reply on Jul 11, 2011 by desc0107
In the script below the processing mask is optional. I am trying to identify if a mask was used or not in the output filename. What I have below is not working as it should, as it stands it adds "Mask" to the filename weather or not a processing mask is used.

The behavior I need is as follows:
If no processing mask is used => add nothing to outputRaster filename.
If processing mask is used => add a string ex.Mask to the outputRasterfilename.

Obviously my code needs tweaking (red)! Any Ideas on how to fix this?

# Import arcpy modules
import arcpy
from arcpy import env
import sys, string, os
arcpy.env.overwriteOutput = True

# Script arguments
inRaster = arcpy.GetParameterAsText(0)
No_STDEV = arcpy.GetParameterAsText(1)
arcpy.env.mask = arcpy.GetParameterAsText(2)# User sets Geoprocessing/Environments/Workspace #(mask is optional)
if not arcpy.Exists(os.path.join((os.path.split(arcpy.env.workspace))[0], 'results')):
   arcpy.CreateFolder_management((os.path.split(arcpy.env.workspace))[0], 'results')
if arcpy.env.mask == "":
   proMask= ""
   proMask= "Mask"
outputRaster= os.path.join(os.path.join((os.path.split(arcpy.env.workspace))[0], 'results'), (os.path.splitext(os.path.basename(inRaster))[0] + "_" + str(proMask) + str(No_STDEV) + "STDEV_" + "enh.tif"))

# Messages to test string concatenation of output file name and folder creation       
arcpy.AddMessage("Name of file to enhance: \n" + inRaster)
arcpy.AddMessage("Name and location of your enhanced image is: \n" + outputRaster)
arcpy.AddMessage("Number of Standard Deviations on the right side to trim histogram: " + No_STDEV)
arcpy.AddMessage("Are you using a processing mask? " + proMask)