In Python 3.6, you can use f-strings like:
>>> date = datetime.date(1991, 10, 12)
>>> f'{date} was on a {date:%A}'
'1991-10-12 was on a Saturday'
I want to overload the method receiving the '%A'
above. Can it be done?
For example, if I wanted to write a dumb wrapper around datetime
, I might expect this overloading to look something like:
class MyDatetime:
def __init__(self, my_datetime, some_other_value):
self.dt = my_datetime
self.some_other_value = some_other_value
def __fstr__(self, format_str):
return (
self.dt.strftime(format_str) +
'some other string' +
str(self.some_other_value
)