User Tools

Site Tools


write_current_date_and_time_to_file_and_screen

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
write_current_date_and_time_to_file_and_screen [2016/08/11 21:54] walkeradminwrite_current_date_and_time_to_file_and_screen [2017/02/04 22:03] – [Write Current Date and Time to File and Screen] walkeradmin
Line 8: Line 8:
 \\  \\ 
 \\  \\ 
 +<sxh [py][; options for SyntaxHighlighter]>
     #!/usr/bin/python     #!/usr/bin/python
     #     #
Line 28: Line 29:
     var=1                           var=1                      
     while var == 1:    # creates a never ending loop     while var == 1:    # creates a never ending loop
-        text = "{:%B %d %Y %H:%M:%S\n}".format(datetime.now())  # make the variable text = the current date and     time. +        text = "{:%B %d %Y %H:%M:%S\n}".format(datetime.now())  # make the variable text = the current  
-    saveFile = open('blt.txt','a'                         # open file for append+                                                                # date and     time. 
 +        saveFile = open('blt.txt','a'                         # open file for append
                  
-    saveFile.write(text)                                    # write date and time (and a new line) to file +        saveFile.write(text)                                    # write date and time (and a new line) to file 
-    saveFile.close()                                        # close the file +        saveFile.close()                                        # close the file 
-     +        
-    print (text)                                            # print date and time (held in var called text) to screen +        print (text)                                            # print date and time (held in var called text) 
-    time.sleep(30)                                           # sleep for x seconds+                                                                # to screen 
 +        time.sleep(30)                                          # sleep for x seconds 
 +</sxh>     
 +\\  
 +==== Example Output ==== 
 +August 11 2016 21:40:12\\  
 +August 11 2016 21:40:42\\  
 +August 11 2016 21:41:12\\  
 +August 11 2016 21:41:42\\  
 +August 11 2016 21:42:13\\  
 +August 11 2016 21:42:43\\  
 +August 11 2016 21:43:13\\  
 +August 11 2016 21:43:43\\  
 +August 11 2016 21:44:13\\  
 +August 11 2016 21:44:43\\  
 +August 11 2016 21:45:13\\  
 +August 11 2016 21:45:43\\  
 +August 11 2016 21:46:13\\  
 +August 11 2016 21:46:43\\  
 +August 11 2016 21:47:13\\  
 +August 11 2016 21:47:43\\  
 +August 11 2016 21:48:13\\  
 +August 11 2016 21:48:43\\  
 +August 11 2016 21:49:13\\  
 +August 11 2016 21:49:43\\  
 +August 11 2016 21:50:13\\  
 +August 11 2016 21:50:43\\  
 +August 11 2016 21:51:13\\  
 +August 11 2016 21:51:43\\  
 +August 11 2016 21:52:13\\  
 +August 11 2016 21:52:43\\  
 +August 11 2016 21:53:13\\  
 +August 11 2016 21:53:43\\  
 +August 11 2016 21:54:13\\  
 +August 11 2016 21:54:43\\  
 +August 11 2016 21:55:13\\  
 +August 11 2016 21:55:43\\  
 +August 11 2016 21:56:13\\  
 +August 11 2016 21:56:43\\  
 +August 11 2016 21:57:13\\ 
 \\  \\ 
 \\  \\ 
- 
write_current_date_and_time_to_file_and_screen.txt · Last modified: 2023/03/09 22:35 by 127.0.0.1