Oct-18-2022, 06:25 AM
Hi,
I have a lot of scripts from which I'd like to know the amount of times it was run.
I coded a working version a long time ago plus I was even more a beginner than I'm currently. So I'll show you what I have, then perhaps you have a better understanding.
Scope:
- several .py-files
- on network location (local)
- multiple users run those files.
- all of these files run my "log" function at the end of the file.
- log function saves to a network .txt file (simple dump).
Function:
pdf 3473 19 February 2020
pdf 3473 19 February 2020
stempel 3496 19 February 2020
status 3496 19 February 2020
My questions:
- which is the better format? I now would say json due the library style
- what if two users run (different) scripts at the same time. Could the file be 'open' thus creating an error? If so: can I catch that?
- is this saving to a network location a good approach?
I have a lot of scripts from which I'd like to know the amount of times it was run.
I coded a working version a long time ago plus I was even more a beginner than I'm currently. So I'll show you what I have, then perhaps you have a better understanding.
Scope:
- several .py-files
- on network location (local)
- multiple users run those files.
- all of these files run my "log" function at the end of the file.
- log function saves to a network .txt file (simple dump).
Function:
def log(): import __main__ project_nummer = projectnumber() date = datetime.now().strftime("%d %B %Y") dyn_naam = os.path.basename(__main__.__file__)[:-10] log_path = "T:\\Folder1\\Folder2\\myscripts.log\\" bestand = log_path + "mylog.txt" input = dyn_naam + "\t" + project_nummer + "\t" + date + "\n" exists = os.path.isfile(bestand) if exists: with open(bestand, "a+") as f: f.writelines(input) return "Log: {} {}".format(log_path, input) else: print "No log file exists"Log file:
pdf 3473 19 February 2020
pdf 3473 19 February 2020
stempel 3496 19 February 2020
status 3496 19 February 2020
My questions:
- which is the better format? I now would say json due the library style
- what if two users run (different) scripts at the same time. Could the file be 'open' thus creating an error? If so: can I catch that?
- is this saving to a network location a good approach?