Let me start with I'm very new to Python so please bare with me. I have created a python script that deletes a feature layer "ElectricMeterDuplicates" out of a GDB, runs some other calculations commands and then exports the results back into the original GDB as a feature layer with the same name. That part is all working correctly until I get to my text file I want to write results to. I could have one of two situations. 1. the new feature layer contains 2 or more rows of data, here I want it to write to the text file the information form 2 fields for each row of data. OR the feature layer is empty and here I want it to write to the file I simple message of no data .
I have written the below script. When I run it in Notebook within Pro it correctly writes to the text file if there is data, however, if there is no data it doesn't write anything. When I run this as a standalone script through a bat file (which is my end goal, the entire thing errors out with ERROR 000732: Input Rows: Dataset ElectricMeterDuplicates does not exist or is not supported and doesn't write anything to the text file no matter the situation.
epath = r"Z:\General\Projects\Utility\Scripts\DuplicateMeters\Logs\ElectricDupMeters.txt"
efile = open(epath, 'a')
etable = r"Z:\General\Projects\Utility\Scripts\DuplicateMeters\DuplicateMeters.gdb\ElectricMeterDuplicates"
fields = ['meternum','assetid']
today = str(date.today())
total = 0
row = arcpy.management.GetCount(
in_rows="ElectricMeterDuplicates"
)
print (row)
if row == 0:
print ("Empty List")
efile.write("No Duplicate Meters on " + today + "\n")
else:
with arcpy.da.SearchCursor(etable,fields) as cursor:
for row in cursor:
print ("Meter {} is duplicated on Asset ID {}".format(row[0],row[1]))
efile.write("Recorded On " + today + " Meter {} is duplicated on Asset ID {}".format(row[0],row[1]) + "\n")
efile.close()