I have a script that runs perfectly in the "Field Calculator." The codeblock looks like this:
def timeday(time, am, diur, pm, noc):
if(time >=am and time < diur):
return "crep_am"
elif(time>= diur and time<pm):
return "diurnal"
elif(time>=pm and time<noc):
return "crep_pm"
else:
return "nocturnal"
and the expression looks like this:
timeday(!LMT_TIME!, !B_C_AM1!, !B_DIUR1!, !B_C_PM1!, !BEG_NOC1!)
As I mentioned, I ran this on a single attribute table for a shapefile and it worked perfectly, but I've never used the python window before. I want to run this code on all of 100 shapefiles. I've been playing around with it, but I can't seem to get it right. Here's what I have so far:
import arcpy
arcpy.env.workspace = r"C:\Users\evan\Desktop\Evan_4-
2017\Deer_Data\LaSal_Deer\GPS_Data\GEO_WGS1984"
Shapefiles = arcpy.ListFeatureClasses("junktest.shp", "junktest2.shp")
codeblock= """def timeday(time, am, diur, pm, noc):
if(time >=am and time < diur):
return "crep_am"
elif(time>= diur and time<pm):
return "diurnal"
elif(time>=pm and time<noc):
return "crep_pm"
else:
return "nocturnal""""
for shp in Shapefiles:
arcpy.CalculateField_management(shp,"TIME_DAY","timeday(!LMT_TIME!, !B_C_AM1!, !B_DIUR1!, !B_C_PM1!, !BEG_NOC1!)","PYTHON", codeblock)
Alternatively, if there is a way to run the field calculator in ArcMap on all of the shapefiles as a batch, I'd be fine with that, but when I tried doing that I was not able to enter my codeblock, only the expression.