Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Problem with Python f-string formatting of struct_time

$
0
0

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.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>