Another surprise from the datetime module

Ben Finney ben+python at benfinney.id.au
Thu Jan 30 23:40:06 EST 2014


Steven D'Aprano <steve+comp.lang.python at pearwood.info> writes:

> On Fri, 31 Jan 2014 11:35:14 +1100, Ben Finney wrote:
>
> > Cameron Simpson <cs at zip.com.au> writes:
> >> 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.
>
> […] What else would you call it?

I'd call it “substitute”, and keep thinking until I came up with
something better.

I wouldn't think very hard, though, because the existing usage of
‘foo.replace’ for a create-new-object-with-different-values method is
fairly well established in the Python built-in types and standard
library. Local expectations do, past some threshold, override general
expectations for the meaning of a term.

-- 
 \       “Everyone is entitled to their own opinions, but they are not |
  `\            entitled to their own facts.” —US Senator Pat Moynihan |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list