Bottom Page

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
Quote
#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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Getting error in finding time.time() value in python Lakshana 1 843 Jan-11-2018, 07:07 AM
Last Post: wavic

Forum Jump:


Users browsing this thread: 1 Guest(s)