Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7522
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python@mrabarnett.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; '(at': 0.03; 'sys': 0.05; 'prints': 0.07; '#print': 0.09; '%s"': 0.09; 'from:addr:python': 0.09; 'valueerror:': 0.09; 'this:': 0.10; 'wrote:': 0.14; '#loop': 0.16; "'r')": 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'miguel': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'reply-to:addr:python-list': 0.16; 'timestamp': 0.16; 'traceback': 0.16; '(most': 0.16; 'convert': 0.19; 'header:In-Reply-To:1': 0.21; 'last):': 0.23; 'received:84': 0.25; 'script': 0.27; 'example': 0.27; "i'm": 0.27; 'raise': 0.28; 'problem': 0.28; 'skip:" 30': 0.29; 'import': 0.29; 'print': 0.31; 'to:addr:python-list': 0.33; 'error': 0.33; 'file': 0.34; 'skip:v 20': 0.34; 'header:User-Agent:1': 0.35; 'skip:" 10': 0.35; 'reply-to:addr:python.org': 0.35; 'data,': 0.36; 'log': 0.36; 'think': 0.38; 'could': 0.38; 'data': 0.38; 'skip:t 40': 0.38; 'skip:t 50': 0.38; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'unix': 0.40; 'help': 0.40; 'skip:2 10': 0.61; 'here': 0.66; 'header:Reply-To:1': 0.72; 'reply-to:no real name:2**0': 0.72 |
| X-IronPort-Anti-Spam-Filtered | true |
| X-IronPort-Anti-Spam-Result | AjgHAKkr9k3Unw4S/2dsb2JhbABSmBaOJHfIMIYkBJYDiw8 |
| Date | Mon, 13 Jun 2011 16:27:55 +0100 |
| From | MRAB <python@mrabarnett.plus.com> |
| User-Agent | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Date2Epoch script |
| References | <COL120-W64F6AB042603E36D1389A0DC690@phx.gbl> |
| In-Reply-To | <COL120-W64F6AB042603E36D1389A0DC690@phx.gbl> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| Reply-To | python-list@python.org |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.174.1307978880.11593.python-list@python.org> (permalink) |
| Lines | 55 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1307978880 news.xs4all.nl 49183 [::ffff:82.94.164.166]:44848 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:7522 |
Show key headers only | View raw
On 13/06/2011 14:03, 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")))
> 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_cdr, "%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
>
I think the problem is that the line in "line_log" ends with "\n",
hence "unconverted data remains:" (at this point it prints the
unconverted data, which is the "\n").
Try this:
timestamp=int(time.mktime(time.strptime(line_log.rstrip(),
"%Y%m%d%H%M%S")))
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Date2Epoch script MRAB <python@mrabarnett.plus.com> - 2011-06-13 16:27 +0100
csiph-web