matthewb

Best practice for paths - arcpy.env.workspace vs os.path.join

Discussion created by matthewb on May 21, 2013
Latest reply on Nov 10, 2016 by CDow-esristaff
Hi,

I've recently had an odd error and found it was due to the way I set up the input. The really odd thing is that some tools worked, but another (arcpy.CalculateStatistics_management) failed with the error:

Failed to execute. Parameters are not valid.
ERROR 000840: The value is not a Mosaic Dataset.
ERROR 000840: The value is not a Mosaic Layer.
ERROR 000840: The value is not a Raster Dataset.

Even though checking the input showed it to be valid raster dataset.

Here's the code that failed:

arcpy.CalculateStatistics_management("demExtract","1","1","#","OVERWRITE")


If I put the full path, it worked. Seems that setting arcpy.env.workspace didn't work for this tool. Using this worked:

arcpy.CalculateStatistics_management((os.path.join(gdbPath, "demExtract")),"1","1","#","OVERWRITE")


Is os.path.join something that should be used by default?

Outcomes