Hi Gary,
thank you for your answer but i'm using int in my file cat 
/tmp/test.log201106121122332011012614553520110126185500

the problem is related to variable "line_log" that i use in the function, 

file_brut = open(log_files_in, 'r')line_log = file_brut.readline()        while 
line_log:                timestamp=int(time.mktime(time.strptime(line_log, 
"%Y%m%d%H%M%S")))
Miguel


Date: Mon, 13 Jun 2011 07:19:54 -0700
From: gher...@islandtraining.com
To: klica_...@hotmail.com
Subject: Re: Date2Epoch script



  


    
  
  
    On 06/13/2011 06:03 AM, miguel olivares varela wrote:
    
      
      

      
      Hello 
      

      
      i try to create
        a script to convert a date "YYYYmmddHHMMSS" as an UNIX
        timestamp. This is an example of my log file 
      
        

          
        cat
            /tmp/test.log
        20110612112233
        20110126145535
        20110126185500
        

        
      
      here is my
        code: 
      

        
      #!
          /usr/bin/python
      

        
      
          import os
          import sys
          import glob
          import re
          import time
          

          
          dir_log = "/tmp"
          #loop to find files log in a directory
        for log_files_in  in
          glob.glob(os.path.join(dir_log, '*.log') ):
                  #print log_files
                  file_brut = open(log_files_in, 'r')
                  line_log = file_brut.readline()
                  while line_log:
                         
            timestamp=int(time.mktime(time.strptime(line_log,
            "%Y%m%d%H%M%S")))
        
    
    

    Did you even bother to examine the results of any of these calls?  
    A simple test like

       >>> time.mktime(time.strptime('20110613010101',
    "%Y%m%d%H%M%S"))

       1307952061.0

    makes it clear that the thing you are passing to int() is in fact
    not an int.

    

    Try removing the '.0', or use int(float(...)).

    

    

    Gary Herron

    

    

    

    

    
      
                          line_log=file_brut.readline()
                          print timestamp
          

          
          

          
          And here the error code: 
          
            

            
            Traceback (most recent call last):
              File "formatage_lms.py", line 32, in ?
                timestamp=int(time.mktime(time.strptime(line_log,
              "%Y%m%d%H%M%S")))
              File "/usr/lib64/python2.4/_strptime.py", line 296,
              in strptime
                raise ValueError("unconverted data remains: %s" %
            ValueError: unconverted data remains:
          
          

          
          

          
          I don't know what i'm diong wrong please could you help
            me
          

          
          Regards
          Miguel
          

          
          

          
        
    
    
                                          
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to