I found a work around to your problem, but it seems way more complex then just writting a log file to keep count of the number of execution. None the less here is the idea, you keep a viariable in your script for the counting of execution. Then when the script finish, you start another task (task scheduler) that modify your first python script to increment the counting variable.
Here is an exemple:
You first script file is: count.py
counting = 0
print(f"Hello im counting {counting}! ")
Then your second python script: countIncrementor.py
with open("count.py") as f:
lines = f.readlines()
newLines = []
newVariable = ""
for line in lines:
if "counting = " in line:
splitLine = line.split()
splitLine[-1] = str(int(splitLine[-1]) + 1)
for i in splitLine:
newVariable += i
newVariable += " "
newVariable = newVariable[0:-1] + "\n"
line = newVariable
newLines.append(line)
with open("count.py", 'w') as f:
for line in newLines:
f.write(line)
When you run the file countIncrementor.py the file count.py will become:
counting = 1
print(f"Hello im counting {counting}! ")
When you execute your script you then have the information on the number of execution.
Or you could overwrite your script file directly (Assuming a script name test.py):
Before:
counting = 0
with open("test.py") as f:
lines = f.readlines()
newLines = []
flag = False
newVariable = ""
for line in lines:
if "counting = " in line:
if not flag:
flag = True
splitLine = line.split()
print(splitLine)
splitLine[-1] = str(int(splitLine[-1]) + 1)
for i in splitLine:
newVariable += i
newVariable += " "
newVariable = newVariable[0:-1] + "\n"
line = newVariable
newLines.append(line)
with open("test.py", 'w') as f:
for line in newLines:
f.write(line)
After:
counting = 1
with open("test.py") as f:
lines = f.readlines()
newLines = []
flag = False
newVariable = ""
for line in lines:
if "counting = " in line:
if not flag:
flag = True
splitLine = line.split()
print(splitLine)
splitLine[-1] = str(int(splitLine[-1]) + 1)
for i in splitLine:
newVariable += i
newVariable += " "
newVariable = newVariable[0:-1] + "\n"
line = newVariable
newLines.append(line)
with open("test.py", 'w') as f:
for line in newLines:
f.write(line)