M
Mark Lawrence
"I had a dangling pointer error, and blew my stack to half past last
wednesday"
IIRC the Germans (possibly amongst others) would say that as half to
last thursday, or is that thurstag?
"I had a dangling pointer error, and blew my stack to half past last
wednesday"
py> divmod(30, 24)
(1, 6)
That makes perfect intuitive sense: 30 hours is 1 day with 6 hours
remaining. In human-speak, we'll say that regardless of whether the
timedelta is positive or negative: we'll say "1 day and 6 hours from now"
or "1 day and 6 hours ago". But when we specify the sign:
py> divmod(-30, 24)
(-2, 18)
If an event happened 30 hours ago, it is correct to say that it occurred
"18 hours after 2 days ago", but who talks that way?
Ah, der neueste und bis heute genialste Streich unsere großenZumindest nicht öffentlich!
Besides, there's an infinite amount of (braindead) timedelta string
representations. For your -30 hours, it is perfectly legal to say
123 days, -2982 hours
Yet Python doesn't (but chooses an equally braindead representation).
Where can I enter a PIP that proposes that all timedelta strings are
fixed at 123 days (for positive, non-prime amount of seconds) and fixed
at -234 days (for all negative or positive prime amount of seconds)?
It's not "equally braindead", it follows a simple and logical rule:
Only the day portion is negative. That might not be perfectly suited
to all situations, but it does mean that adding and subtracting whole
days will never change the representation of the time. That's a
reasonable promise.
What you propose is completely arbitrary,
Doesn't need a PEP. Just subclass it or monkey-patch it and use it as
you will.
Ah, der neueste und bis heute genialste Streich unsere großenZumindest nicht öffentlich!
It's not "equally braindead", it follows a simple and logical rule:
Only the day portion is negative.
Ah, der neueste und bis heute genialste Streich unsere großenZumindest nicht öffentlich!
Why would the stability of the *string* output of the time
representation be of any interest whatsoever? Do you have any even
halfways reasonable usecase for that?
No. What I propose is that for t > 0 this holds:
"-" + str(t) == str(-t)
Which is far from arbitrary.
It follows "natural" rules of inverting
something (-abs(x) == -x), and it yields a (truly) human-readable form
of showing a timedelta.
Please don't mix this up with the very apparent braindead proposal of
mine. In case you didn't notice, this was irony at work. The word
"braindead" I chose to describe the format should have tipped you off to
that.
Nonono, you misunderstand: I want everyone to suffer under the braindead
representation, just as it is now!
And it makes it extremely error-prone to the reader:
'-1 day, 23:59:59'
This looks MUCH more like "almost two days ago" than
'-00:00:01'
does.
There are,
as I see it, two common cases where t is negative:
-1 day < t < 0
and
t <= -1 day
It's not "equally braindead", it follows a simple and logical rule:
Only the day portion is negative.
That might not be perfectly suited to all situations
What you propose is completely arbitrary, and yes
it WOULD be braindead to have str() return that
There are two types of negative numbers: Those closer to zero than -1,
and those not closer to zero than -1. Yeah, I think those are the most
common cases.
Skip Montanaro said:Feel free to submit a patch to improve str(t), where t is negative,
Simple and logical, yes. But also entirely braindead.
Give ma a real-life situation where you would want such behavior.
I don't recall specifics, but I do remember multiple times
where I was working with a structure that consisted of
a whole part and a fracture part where I found it useful
to have the fracture part always positive and displayed
as such.
In any case... what I'd suggest would be opening a tracker issue, or
discussing this on python-ideas, and seeing what core devs think of
the matter. I think that, on balance, it's probably better to show the
whole thing with the same sign; but should it be:
'-1 day, 00:00:01'
or should the hyphen be repeated:
'-1 day, -00:00:01'
Simple and logical, yes. But also entirely braindead.
Give ma a real-life situation where you would want such behavior.
Before doing so, I suggest looking for the design discussion either on the tracker or in python-ideas or py-dev lists.
'-(1 day, 00:00:01)' should be unambiguous.
Steven D'Aprano said:Do you think it is "braindead" for __str__ to return something which
follows the internal representation of the object?
Easy -- I'm debugging timedelta routines, and I want to easily see that
the timedeltas calculated match what I expect them to be when I print
them. The quickest, easiest and simplest way is for str(timedelta) to
follow the internal representation.
Oh look, that's exactly what the docs say:
"String representations of timedelta objects are normalized similarly to
their internal representation. This leads to somewhat unusual results for
negative timedeltas."
Before doing so, I suggest looking for the design discussion either on
the tracker or in python-ideas or py-dev lists.
Terry Reedy said:And skip the troll word 'braindead'.
Terry Jan Reedy
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.