How to write time (local system time), in text file or in log file using a Python script?
Question: I have to write a test case, for that I am using sikuli which works on a
Python script, here I am not able to write local system time in text file.

    
    
    import time;
    
    localtime = time.localtime(time.time())
    inp=file("C:\\Users\\%path%\\Log.txt", 'w')
    inp.write('************** Full Process ****************\n')
    inp.write('Local current time :', localtime)  incorrect
    

Here I am creating a .txt file and also I have to write time and I don't know
how to write the code.


Answer: That's pretty much correct, but you have an error writing the time:

    
    
    inp.write('Local current time :', localtime)
    

If you want to format a string like that, you need to use the `%` operator:

    
    
    inp.write('Local current time : %s' % localtime)
    

Furthermore, just printing the Time object will print a very weird string. You
want to write the date in a more convenient way, by example YYYY/MM/DD -
HH:MM:SS. You do it like this:

    
    
    localtime.strftime ('%Y/%m/%d - %H:%M:%S')
    

So your piece of code will be:

    
    
    import time
    
    localtime = time.localtime(time.time())
    timestring = time.strftime ('%Y/%m/%d - %H:%M:%S')
    inp=file("Log.txt", 'w')
    inp.write('************** Full Process ****************\n')
    inp.write('Local current time : %s' % timestring)
    

