I want to creat file with each line having date + time + data so I can append more data as need be and know when it was added. What date+time function would be best?
I just was messing around with the time module tonight. are you asking for something simple like
>>> import time >>> time.ctime() 'Mon Oct 24 23:30:47 2005'
That would do it - but maybe a little shorter is even better.
how about this
import time # time.localtime() splits the time into elements of a tuple tuple_time = time.localtime() # don't europeans do day/month/year ? time_stamp = "%s:%s %s/%s/%s" %(tuple_time, tuple_time, tuple_time, tuple_time, tuple_time) print time_stamp
edit added later//
I noticed a time like one minute after 12 looks like this
that could be fixed with a little more code
this code fixes that issue
def time_stamp(): import time tuple_time = time.localtime() hours = tuple_time if int(hours) in range(10): hours = "0%s" %hours minutes = tuple_time if int(minutes) in range(10): minutes = "0%s" %minutes day = tuple_time month = tuple_time year = tuple_time # don't europeans do day/month/year ? time_ = "%s:%s %s/%s/%s" %(hours, minutes, day, month, year) return time_
That looks good. Many countries in Europe have day/month/year format, but that doesn't make much sense for what I may want to do. I am thinking about a date and time stamp starting each data line where the line could be sorted. It could have to look something like year/month/day hour:minute:second to do this rightly.
The tuple_time almost has this sorting format.