I have the following code;
oStat=os.stat(oFile)
print(time.strftime('%H:%M:%S', time.localtime(oStat.st_mtime)))
print(f"{time.localtime(oStat.st_mtime):%H:%M:%S}")
The first print statement works as expected; the f-string gives me:
print(f"{time.localtime(oStat.st_mtime):%H:%M:%S}")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unsupported format string passed to time.struct_time.__format__
The desired output should be a time eg:
14:10:02
Why is this in error and how can I fix it?
I've tried various combinations but none work.
datetimeordateobjects from thedatetimemodule. Thetime.localtimefunction returns a low-level type which doesn't support formatting.struct_timejust inheritsobject.__format__, which doesn't support any kind of format modification: it only accepts the empty string as an argument.:to "introduce" a format specification, but that specification must be empty:f'{time.localtime(...):}'is valid, but nothing more complicated is.)