Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65031

Re: Another surprise from the datetime module

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '(at': 0.04; 'from:addr:yahoo.co.uk': 0.04; 'attribute': 0.07; 'string': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:module': 0.09; 'python': 0.11; 'language.': 0.14; 'easier.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'roy': 0.16; 'seconds.': 0.16; 'strftime': 0.16; 'language': 0.16; 'wrote:': 0.18; 'print': 0.22; 'header:User-Agent:1': 0.23; 'either.': 0.24; "i've": 0.25; 'least': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply- To:1': 0.27; "doesn't": 0.30; 'work.': 0.31; 'easier': 0.31; 'figure': 0.32; 'plain': 0.33; 'skip:t 40': 0.33; 'subject:the': 0.34; 'subject:from': 0.34; 'but': 0.35; 'there': 0.35; 'method': 0.36; 'to:addr:python-list': 0.38; 'that,': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'most': 0.60; 'mentioned': 0.61; 'our': 0.64; 'smith': 0.68; 'discover': 0.82; "shouldn't,": 0.84; 'received:89': 0.85; 'wanting': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Another surprise from the datetime module
Date Thu, 30 Jan 2014 18:03:17 +0000
References <lce2bf$4fo$1@panix2.panix.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host host-89-240-160-29.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
In-Reply-To <lce2bf$4fo$1@panix2.panix.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.6154.1391105019.18130.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1391105019 news.xs4all.nl 2950 [2001:888:2000:d::a6]:53719
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:65031

Show key headers only | View raw


On 30/01/2014 17:32, Roy Smith wrote:
> I was astounded just now to discover that datetime.timedelta doesn't
> have a replace() method (at least not in Python 2.7).  Is there some
> fundamental reason why it shouldn't, or is this just an oversight?
>
> My immediate use case was wanting to print a timedelta without the
> fractions of seconds.  The most straight-forward is:
>
> print td.replace(microseconds=0)
>
> but that doesn't work.  Yes, I know I can use strftime, but (as I've
> mentioned before :-)), that requires dragging up the reference page to
> figure out what grotty little format string I need.  The brute-force
>
> print timedelta(seconds=int(td.total_seconds()))
>
> is easier than that, but plain old replace() would be even easier.
>

datetime.timedelta doesn't have a strftime method either.

AttributeError: 'datetime.timedelta' object has no attribute 'strftime'

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Another surprise from the datetime module roy@panix.com (Roy Smith) - 2014-01-30 12:32 -0500
  Re: Another surprise from the datetime module Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-30 18:03 +0000
  Re: Another surprise from the datetime module Neil Cerutti <neilc@norwich.edu> - 2014-01-30 18:36 +0000

csiph-web