[Python-ideas] strptime without second argument as an inverse to __str__

Terry Reedy tjreedy at udel.edu
Wed Aug 6 21:26:16 CEST 2014


On 8/6/2014 12:47 PM, Alexander Belopolsky wrote:
>
> On Wed, Aug 6, 2014 at 12:20 PM, Wolfgang Maier
> <wolfgang.maier at biologie.uni-freiburg.de
> <mailto:wolfgang.maier at biologie.uni-freiburg.de>>
> wrote:
>
>     BTW, Terry's suggestion of datetime.fromstr(s) sounds very reasonable.
>
>
> We don't have int.fromstr, float.fromstr, or in fact a .fromstr
> constructor for any other type.  IMO, date(str) is "the obvious way to
> do it."

There are two parts to my suggestion. The first is to focus on the 
original goal of the thread, 'an inverse to __str__', and only that, not 
on automatically parsing, without providing a format, larger classes of 
possible strings.

The second is to suggest a better spelling for that original goal than 
the original proposal (strptime without second argument) or alternate 
proposals like .fromisostring based on an expanded goal. I think 
'.fromstr' is the best possible spelling among '.from...' choices.

If instead using the standard constructor works, fine with me.  I am not 
sure of the criterion for adding alternative to .__init__ versus an 
alterntive method.

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list