In many Esri examples, including this one, they code in the output ".shp". What is the best way if you want to be able to handle a shapefile OR a feature class output. Let say if a GDB is provided as the workspace, then features class, if a folder directory then .shp. Is there any ArcPy built-in to handing this?
As commented, it doesnt matter. Just supply the path and ~filename without the
.shp extension and arcpy will know what to do.
- With a folder named data
r"C:\GIS\data\outputdataset"a shape named
outputdataset.shp(and all other shape extensions) will be created in it
- If the output is a database, like a file geodatabase arcpy will create a feature class in it, example: