In a nutshell, I need to reverse the operation of Python f-string
.
Using this formatter, in Python you can easily build arbitrary strings from variables that contain dates. For example:
f"{day}-{mon}-{year} \n {hour}:{minute}some silly\n text here_{seconds}"
where year
etc. are integers that represent what you'd expect.
Now, I need a function that is able to do the reverse operation, i.e. given a string formatted in a funny (but known) way, retrieve the underlying date variables. Something like this:
def retrieve_date(str_date, str_format):
# str_date is 27-03-2021 \n 04:11:some silly\n text here_34"
# str_format is something like "{day}-{mon}-{year} \n {hour}:{minute}some silly\n text here_{seconds}"
# some logic
# return the 6 integers that make up the time stamp
return year, month, day, hour, minute, second
How can this be done in Python?