Python does not let me format time.

Bjorn Pettersen bjorn at roguewave.com
Fri Apr 28 02:40:48 CEST 2000


Sindh wrote:
> 
> Hi folks
> 
> I have a file full of date, value pairs. Date is like MM/DD/YY. My
> problem is I want to format this file since it contains a few thousand
> lines of data , using python. I tried using string and time modules. I
> want to format the time value to a float which is returned by
> time.gmtime normally. I tried to split it and to use parts of it to make
> a tuple and to use time.mktime but it says illegal operation for
> builtin.
> 
> Summary:
> 
> data is:
>         03/11/98 abcd
>         03/12/98 efgh
> 
> I split it to
>         x=string.split(n[0],' ')
>         which gave me x='03/11/98'
> Now I split it again by
>         x=string.split(x,'/')
>         which gave a tuple of '03','11','98'
> Now I tried  to make time as
> time.mktime(x[2],x[0],x[1],'','','','','','')
> The problem is it says illegal operation for builtin. I tried to use the
> string val and int val as the arguments for mktime.
> 
> Anyone with any helpful ideas!!
> 
> If there is already a moduls to do the same , much helpful.

time.mktime() needs integer arguments, and the result of string.split is
a list of strings.  Changing it to:

  time.mktime(int(x[2]),int(x[0]),int(x[1]),0,0,0,0,0,0)

should probably work (I didn't check how many arguments it requires ;-)

-- bjorn




More information about the Python-list mailing list