Python time - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Python time (/thread-24446.html) |
Python time - SamAnw - Feb-14-2020 Hello everyone, I need to create a program that converts an input like this one: 1m and 45s 10m,10s 32s, and 12h 76h 1s Into an output like this one: 00:01:45 00:10:10 12:00:32 76:00:00 00:00:01 Does anyone have an idea of how to do this in a file.read? Thanks in advance RE: Python time - ThiefOfTime - Feb-14-2020 since your input can vary a lot but all have in common that you either have the m, s or h part, you could use regex to filter them out. for example lets say you have following line in your document "10m,10s" import re print(re.findall("[0-9]?[0-9][m,s,h]", "10m,10s")) From there your could build your desired output :)P.S.: The regex currently only works if all numbers are lower than 100 |