Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python time
#1
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
Reply
#2
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"))
Output:
["10m", "10s"]
From there your could build your desired output :)

P.S.: The regex currently only works if all numbers are lower than 100
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to change UTC time to local time in Python DataFrame? SamKnight 2 1,527 Jul-28-2022, 08:23 AM
Last Post: Pedroski55
  Getting error in finding time.time() value in python Lakshana 1 2,463 Jan-11-2018, 07:07 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020