I have written a script using ArcPy commands that, in short, randomly generates points in several areas, merges them, adds XY coordinates to the merged points, and exports them with the "ExportXYv_stats" command. This script works perfectly fine if I run it once. However, whenever I try to add a 'for loop' to do this several times, ArcMap v10.4 crashes after completing the "Export" command. No error is visible before the crash occurs. Example code:
for x in range(0, 3):
... (extraneous code)...
output_file = "Filename%d.txt" % x
The program crashes here. It will export the output file correctly, but the program completely halts afterwards (print statements placed immediately after the command do not get printed), and ArcMap crashes. If I comment out the export command, the program loops without issue. If I remove the loop, the program does not crash.
I am at a loss of why this would be happening. Any suggestions would be appreciated.