James- Along with what @Randy_Burton suggests, using
import arcpy
arcpy.env.workspace = r'X\some\path\to\your.gdb'
sets it explicitly. With ListFeatureClasses and ListTables() both need the workspace set as shown above, and I don't think either of them take an argument. If you are going to set a workspace with env and copy data to a different out workspace, just set a variable:
arcpy.env.workspace = r'T:\GIS Documents\MOW\SDE_Surrogate.gdb'
outWS = r'T:\GIS Documents\MOW\ClientCount.gdb'
fields = ['Month','Year']
arcpy.SplitByAttributes_analysis('MasterDelivery2018',outWS,fields)
Notice how line one sets the env while line 2 sets where I want the output of SplitByAttributes() to go.
Another example:
arcpy.env.workspace = r'T:\GIS Documents\MOW\ClientCountSum2.gdb'
outWS = arcpy.env.workspace
inFeatures = r'I:\GIS\ArcSDE\SuperUser\is\slco@slcopub.sde\slcopub.SLCO.Administration\slcopub.SLCO.ZipCodes'
layerName = 'zipLayer'
joinField1 = 'ZIP_CD'
joinfield2 = 'FIRST_Residential_Zipcode'
for t in arcpy.ListTables():
try:
joinTable = t
outFeature = '{}\{}joined'.format(outWS,t)
arcpy.MakeFeatureLayer_management (inFeatures, layerName)
arcpy.AddJoin_management(layerName, joinField1, joinTable, joinfield2)
arcpy.CopyFeatures_management(layerName, outFeature)
print('Success: created month feature class')
except Exception as err:
print('Error')
print(err)
Line 2 sets the outWS explicitly so I can use it a little later in line 11 where I name the out feature class using the original table name with the word 'joined' pasted to the end of it.
and finally, one more example I just wrote for the same meals on wheels project I working on:
arcpy.env.workspace = r'T:\GIS Documents\MOW\ClientCountSum2.gdb'
target = r'T:\GIS Documents\MOW\SDE_Surrogate.gdb\ClientCountByZip'
for x in arcpy.ListFeatureClasses():
arcpy.Append_management(x,target,'NO_TEST')
Glad to see you are writing python at your new job!
That should just about do it....