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


Groups > comp.lang.python > #65075

Re: Another surprise from the datetime module

From Ben Finney <ben+python@benfinney.id.au>
Subject Re: Another surprise from the datetime module
Date 2014-01-31 11:35 +1100
References <lce63h$c88$1@ger.gmane.org> <20140131000631.GA69776@cskk.homeip.net>
Newsgroups comp.lang.python
Message-ID <mailman.6184.1391128528.18130.python-list@python.org> (permalink)

Show all headers | View raw


Cameron Simpson <cs@zip.com.au> writes:

> Hmm. I do not like the replace() as suggested.
>
> Firstly, replace is a verb, and I would normally read
> td.replace(microseconds=0) as an instruction to modify td in place.
> Traditionally, such methods in python return None.

I agree with this objection. A method that is named “replace”, yet does
not modify the object, is badly named.

However, the existing ‘replace’ methods ‘datetime.date.replace’,
‘datetime.datetime.replace’, ‘datetime.time.replace’ already work this
way: they create a new value and return it, without modifying the
original object.

    <URL:http://docs.python.org/3/library/datetime.html#datetime.date.replace>
    <URL:http://docs.python.org/3/library/datetime.html#datetime.datetime.replace>
    <URL:http://docs.python.org/3/library/datetime.html#datetime.time.replace>

So, if ‘datetime.timedelta.replace’ were to be implemented (I'm not
convinced it is needed), it should have that same behaviour.

-- 
 \      “I tell you the truth: this generation will certainly not pass |
  `\           away until all these things [the end of the world] have |
_o__)   happened.” —Jesus Christ, c. 30 CE, as quoted in Matthew 24:34 |
Ben Finney

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


Thread

Re: Another surprise from the datetime module Ben Finney <ben+python@benfinney.id.au> - 2014-01-31 11:35 +1100
  Re: Another surprise from the datetime module Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-31 03:53 +0000
    Re: Another surprise from the datetime module Roy Smith <roy@panix.com> - 2014-01-30 22:58 -0500
    Re: Another surprise from the datetime module Ben Finney <ben+python@benfinney.id.au> - 2014-01-31 15:40 +1100
  Re: Another surprise from the datetime module Dan Sommers <dan@tombstonezero.net> - 2014-01-31 04:04 +0000

csiph-web