Sorry, I should have included my entire PY, I had arcpy in there and
Sorry i Don't know how to to add code brackets in replies like in the original question.
<python>
# This Project was developed as a tool to create 24 traffic accident maps for the lights for lives video completed Weekly
#Import Modules
from datetime import *; from dateutil.relativedelta import*
import arcpy, os, moviepy.editor as mpy
import numpy
# Set Variables
mxdpath = r'MXD Location' # This is the path of the map that is the base for this Script
outputfolder = r"Output folder"+"".join(str(date.today()))+"\\" # This is the Output folder
hourdriver = range(1) # This Project creates 24 maps
trafficquery = "nature LIKE 'TA%' AND CallDate > GETDATE() - 90 AND Datepart(hh, CallDate) = " #This sets the Query for the Traffic Accident(TA) Layer in the map
coronerquery = "nature = 'ZZ - CORACCIDEN ' AND factor = 'CLASS OF DEATH ' AND method = 'MOTOR VEH CRASH ' AND Year (Occured ) = 2015 AND Datepart(hh, Occured ) = " #This Sets the Query for the Coroner Map(CR) layer in the map
timelist = ["12:00am - 01:00am","01:00am - 02:00am","02:00am - 03:00am","03:00am - 04:00am","04:00am - 05:00am",\
"05:00am - 06:00am","06:00am - 07:00am","07:00am - 08:00am","08:00am - 09:00am","09:00am - 10:00am",\
"10:00am - 11:00am","11:00am - 12:00pm","12:00pm - 01:00pm","01:00pm - 02:00pm","02:00pm - 03:00pm",\
"03:00pm - 04:00pm","04:00pm - 05:00pm","05:00pm - 06:00pm","06:00pm - 07:00pm","07:00pm - 08:00pm",\
"08:00pm - 09:00pm","09:00pm - 10:00pm","10:00pm - 11:00pm","11:00pm - 12:00am"]
# Check for an output folder and complete
if not os.path.exists(outputfolder):
os.makedirs(outputfolder)
else:
exit("Folder already exists")
mxd = arcpy.mapping.MapDocument(mxdpath)
# loop through hours for each layer and export to .png
for step in hourdriver:
for lyr2 in arcpy.mapping.ListLayers(mxd,"CR"):
lyr2.definitionQuery = coronerquery+"".join(str(step))
print lyr2.definitionQuery # added for diag
for lyr in arcpy.mapping.ListLayers(mxd,"TA"):
lyr.definitionQuery = trafficquery+"".join(str(step))
print lyr.definitionQuery # added for diag
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if elm.name == "TIME_DESC":
print "Found it"
elm.text = timelist[step]
print elm.text
filename = outputfolder+"".join(str(step))+""".png"""
print filename
mxd.save()
arcpy.mapping.ExportToPNG(mxd,filename)
print "Done with Maps"
</python>
Thank you for your help