mktime and tupples

Rico Albanese r.albanese at qut.edu.au
Thu Oct 28 00:21:59 EDT 1999


Hi everyone,

I am writing a web application and I am trying to get a string which
represents a date (eg. 16071999) and generate from this the
corresponding Unix Time in secs from Epoch.  So with the following code
I am trying to generate a tuple which is suitable to pass to
time.mktime() as a parameter.  I have imported all of the required
modules but the following code bombs out at the line "thetime=...".  Are
the variables y, m, d strings? How do I create a tuple (ie. variable
"atime" below) so that it is a valid parameter for time.mktime()?  Here
is my code :

yr=re.search('[0-9]{1,4}$',c_date)  #pull year from 16071999 eg. 1999
dymnth=re.search('^[0-9]{1,4}',c_date)  #pull out day/month from
16071999 eg. 1607
daymonth=dymnth.group()
dy=re.search('^[0-9]{1,2}',daymonth)  #pull out day from 16071999 eg. 16

mnth=re.search('[0-9]{1,2}$',daymonth)  #pull out month from 16071999
eg. 07
y=yr.group()
m=mnth.group()
d=dy.group()
atime=(y,m,d,0,0,0,0,0,0)
thetime=time.mktime(atime)

Thanks in advance for any assistance.

Rico






More information about the Python-list mailing list