4 ms·
Here's an amusing code snippet for you: >>> (datetime.datetime.now() - datetime.timedelta(days=2007)).__str__() '2008-05-14 18:32:57.195554' Looks lik
by shadowmint 13y ago
Here's an amusing code snippet for you:
>>> (datetime.datetime.now() - datetime.timedelta(days=2007)).__str__()
'2008-05-14 18:32:57.195554'
Looks like this old goldy originally turned up when hacker news was just a yearling...
https://news.ycombinator.com/item?id=188873 https://news.ycombinator.com/item?id=188873
- masklinn 13y ago... why would you call `__str__` explicitly instead of 1. using str() as you're supposed to or 2. just using print?
- olalonde 13y ago... and Poe's law strikes again.
- JoachimSchipper 13y agoThat's partially true, but note that Python does, to a fairly large extent, have One True Way of formatting code (i.e. PEP-8). Although, amusingly, I can't actually find this rule in PEP-8.
- masklinn 13y agoNot calling dunder methods directly doesn't really need to be in PEP8, they're data model methods for overloading protocols, their whole purpose is to be used by some other "top-level" operation if and when necessary (nb: this may or may not apply when implementing or overloading dunder methods, but that's a special case)
- cocoflunchy 13y agoMaybe he was in the REPL and found himself at the end of the line, and didn't want to go back to the beginning, so he appended .__str__() instead.