| | |
Create text file
Thread Solved |
•
•
Join Date: Feb 2008
Posts: 198
Reputation:
Solved Threads: 0
Hi All,
I am using the below code to write into a text file
The text file 'Log.txt' is present in 'Doc' folder inside the application folder.
Now I want to create a text file with a time stamp every time the User runs the application and then write contents into it. How do I do this?
Any help is much appreciated!...
Regards,
Dinil
I am using the below code to write into a text file
Python Syntax (Toggle Plain Text)
# Write into log file inp=file(Doc\Log.txt, 'w') inp.write('Log file start') inp.close()
The text file 'Log.txt' is present in 'Doc' folder inside the application folder.
Now I want to create a text file with a time stamp every time the User runs the application and then write contents into it. How do I do this?
Any help is much appreciated!...
Regards,
Dinil
Here's an example of how to get the current date and time (as a string) using the datetime module.
Hope that helps!
python Syntax (Toggle Plain Text)
import datetime timestamp = str(datetime.datetime.now()) """result -> '2009-07-08 01:16:25.968000' """
"Two good old boys in a fire-apple red convertible. Stoned. Ripped. Twisted. Good people."
- Hunter S. Thompson
my photography
- Hunter S. Thompson
my photography
•
•
Join Date: Feb 2008
Posts: 198
Reputation:
Solved Threads: 0
Thanks... i used the below code and its working perfectly..
Thanks a lot
Thanks once again!
Thanks a lot
Python Syntax (Toggle Plain Text)
lt = time.localtime(time.time()) lt=[lt[1], lt[2], lt[0], lt[3], lt[4],lt[5]] lt=str(lt[0])+"-"+str(lt[1])+"-"+str(lt[2])+"-"+str(lt[3])+"hr"+str(lt[4])+"min"+str(lt[5])+"s" strFile = "Log"+"_"+str(lt)+".txt" file = open(strFile , "a") file.write('Log file starts') file.close()
Thanks once again!
•
•
Join Date: Apr 2009
Posts: 44
Reputation:
Solved Threads: 10
you can also try this it would constitute for a lot less coding
python Syntax (Toggle Plain Text)
import time #here you can format the date string anyway you want time_stamp = time.strftime('%Y-%m-%d %H:%M:%S', (time.localtime(time.time()))) #output for time_stamp -> '2009-07-08 14:22:41' #and format the text file name like such strFile = "Log_%s.txt"%time_stamp
Last edited by baki100; Jul 8th, 2009 at 9:22 am.
![]() |
Similar Threads
- Unable to right click and create new text file? (Windows NT / 2000 / XP)
- How to create a text file and place in specific location (windows xp) (C++)
- I want to create text file on clients local drive.Please help. (ASP.NET)
- turning userinput into a text file (C)
- How do you create a text file? (C)
- Output in Text file-How to apply fprintf()? (C)
- 10 line text file (Java)
Other Threads in the Python Forum
- Previous Thread: binary strings
- Next Thread: Run user given python scripts
| Thread Tools | Search this Thread |
abrupt accessdenied anti apache application approximation argv array beginner book builtin calculator change converter countpasswordentry curved dan08 dictionaries dictionary dynamic edit enter examples file float format function gui heads homework import inches input java keyboard lapse launcher library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric output parameters parsing path phonebook plugin port prime programming projects py2exe pygame pyopengl python random recursion redirect remote reverse scrolledtext session simple software sprite statictext statistics string strings syntax table terminal text textarea threading time tlapse trick tuple tutorial twoup ubuntu unicode unit urllib urllib2 variable wordgame wxpython





