Python Forum
Saving the times a script is run to a file or ...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Saving the times a script is run to a file or ...
#1
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:
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?
Reply


Messages In This Thread
Saving the times a script is run to a file or ... - by 3Pinter - Oct-18-2022, 06:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Music Python Script Repeating Number When Saving Facebook Photos ThuanyPK 2 241 May-13-2024, 10:59 PM
Last Post: ebn852_pan
  Code Assistance needed in saving the file MithunT 0 874 Oct-09-2022, 03:50 PM
Last Post: MithunT
  Saving the print result in a text file Calli 8 2,017 Sep-25-2022, 06:38 PM
Last Post: snippsat
  Trying to determine attachment file type before saving off.. cubangt 1 2,279 Feb-23-2022, 07:45 PM
Last Post: cubangt
  Showing and saving the output of a python file run through bash Rim 3 2,632 Oct-06-2021, 10:48 AM
Last Post: gerpark
  Problem in saving .xlsm (excel) file using pandas dataframe in python shantanu97 2 4,541 Aug-29-2021, 12:39 PM
Last Post: snippsat
  Need help with saving output into an excel file Beyondfacts 4 3,068 Mar-22-2021, 11:51 AM
Last Post: jefsummers
  Automating to run python script 100 times by changing parameters pmt 1 2,676 Dec-29-2020, 10:31 AM
Last Post: andydoc
  Saving text file with a click: valueerror i/o operation on closed file vizier87 5 4,577 Nov-16-2020, 07:56 AM
Last Post: Gribouillis
  Copy mp3 file multiple times and rename Mar10 4 3,889 Sep-23-2020, 01:09 AM
Last Post: Mar10

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020