Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'yet.': 0.04; 'string': 0.09; 'function,': 0.09; 'subject:string': 0.09; 'to:addr:pobox.com': 0.09; 'to:addr:skip': 0.09; 'cc:addr:python- list': 0.11; 'changes': 0.15; '23,': 0.16; '32,': 0.16; 'accepts': 0.16; 'wrote:': 0.18; 'looked': 0.18; '>>>': 0.22; 'email addr:gmail.com>': 0.22; 'handles': 0.22; 'cc:addr:python.org': 0.22; '>>>': 0.24; 'parse': 0.24; 'skip': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'cool,': 0.31; 'ones.': 0.31; 'sep': 0.31; 'skip:d 20': 0.34; "i'd": 0.34; 'subject:with': 0.35; 'created': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; "didn't": 0.36; 'thanks': 0.36; "i'll": 0.36; 'feed': 0.38; 'pm,': 0.38; 'little': 0.38; 'tell': 0.60; 'back': 0.62; 'more': 0.64; 'different': 0.65; 'study': 0.69; 'hood': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=Mjn2ebmIDfiJ+JJPvrb9laoh42X1RmGbkaYBLI2lCtc=; b=ib714+KbvG9BHvlEJeGPa6epr3U2nkLnEOwOEoyxyjjpHBuZFJvml3kmh94indpqHW j7l+TO+g4ZXMFksiyKgBUvCSvjil8UQNAMKMzjX9RacwTnexS+6kC6HxmV5q5/R75Lqc f5GfsQyeXDj9W3OAP6aFfYqeP+KF64UaX50VJEYb6NcBmPD5IzhEXkx7Fq0EKcyB/3ER jyIfW6WBUvDZPKwfzxl+1500t4YxVn3cNdVGmYsHN70Burc/dIZHzY48IGvdN6OOISnH 64qstUVw6s0bSQle6ESThgNogd2rZ1c5zNF+8lLZG2p1UarBoSmiMkr2Gcpny0UUTQYP VLdQ== X-Received: by 10.180.84.193 with SMTP id b1mr25044793wiz.40.1411492563207; Tue, 23 Sep 2014 10:16:03 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Felipe Menezes Machado Date: Tue, 23 Sep 2014 19:15:43 +0200 Subject: Re: Timedelta constructor with string parameter To: Skip Montanaro Content-Type: multipart/alternative; boundary=f46d04374501d54c790503beb83d Cc: Python X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 68 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1411492570 news.xs4all.nl 2835 [2001:888:2000:d::a6]:49214 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:78228 --f46d04374501d54c790503beb83d Content-Type: text/plain; charset=UTF-8 On Tue, Sep 23, 2014 at 6:39 PM, Skip Montanaro wrote: > > On Tue, Sep 23, 2014 at 4:11 AM, wrote: > >> I created some code recently to parse a string and create a timedelta >> from it. > > > Interesting. I notice that dateutil.parser.parse already understands you > notation: > > >>> x = dateutil.parser.parse("5h32m15s") > >>> x > datetime.datetime(2014, 9, 23, 5, 32, 15) > > All that would be necessary is some way to tell it to generate a timedelta > instead of a datetime. Might be better to feed changes back to the dateutil > package maintainers. > > Cool, thanks for the tip, I didn't know dateutil yet. I looked at the code for the dateutil.parser.parse function, and under the hood it is so much more than my function does. It accepts many different formats, and also handles timezones. So I'd have to study it a little to think of a way for it to generate timedelta objects instead of datetime ones. But I'll definitely keep that in mind! Felipe --f46d04374501d54c790503beb83d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On T= ue, Sep 23, 2014 at 6:39 PM, Skip Montanaro <skip@pobox.com> = wrote:

On Tue, Sep 23, 2014 at 4:11 AM, = <felipou@gmail.com> wrote:
I created som= e code recently to parse a string and create a timedelta from it.

Interesting. I notice that dateutil.parser.parse already under= stands you notation:

>>> x =3D dateutil.par= ser.parse("5h32m15s")
>>>= ; x
datetime.datetime(2014, 9, 23, 5, 32, 1= 5)

All that would be necessary is some way to tell= it to generate a timedelta instead of a datetime. Might be better to feed = changes back to the dateutil package maintainers.


Cool, thanks for the tip, I didn't know= dateutil yet.

I looked at the code for the dateut= il.parser.parse function, and under the hood it is so much more than my fun= ction does. It accepts many different formats, and also handles timezones. = So I'd have to study it a little to think of a way for it to generate t= imedelta objects instead of datetime ones. But I'll definitely keep tha= t in mind!

Felipe
--f46d04374501d54c790503beb83d--