0

我知道必须有几种方法可以做到这一点,但我很想听听你的意见,哪种方法是最好的方法。

我有一个 .csv,从手机的秒表应用程序输出,如下所示:

No.,Split time,,
1,+03:16.110,,
2,+12:23.120,,
3,+15:36.187,,
4,+16:56.487,,
5,+19:30.488,,
6,+20:01.621,,
 [...]
37,+53:01.921,,
38,+53:39.738,,
39,+53:40.241,,
40,+01:06.849,,
41,+01:16.442,,

我需要将秒表时间码更改为小时:分钟:秒:帧格式,删除列标题,添加额外信息并考虑小时翻转(从第 40 行开始)。

因此,输出将如下所示:

cut_v01 00:03:16:00 V4  black                  
cut_v01 00:12:23:00 V4  black                  
cut_v01 00:15:36:00 V4  black                  
cut_v01 00:16:56:00 V4  black                  
cut_v01 00:19:30:00 V4  black                  
cut_v01 00:20:01:00 V4  black                  
 [...]         
cut_v01 00:53:01:00 V4  black                  
cut_v01 00:53:39:00 V4  black                  
cut_v01 00:53:40:00 V4  black                  
cut_v01 01:01:06:00 V4  black                  
cut_v01 01:01:16:00 V4  black                  

最有效的方法是什么?

4

1 回答 1

0

弄清楚了 -

import string, sys, os

def convert_stopwatch(in_filename): 
   new_filename=in_filename.replace("Stopwatch", "Timecode")

   SW_lines=open(in_filename,'Ur').readlines() 
   timecode=open(new_filename, 'w') 

   previous_minutes = 0  
   hours = 0

   for SW_line in SW_lines:
            plus_pos = SW_line.find("+")      
            if plus_pos > -1: 
                dot_pos = SW_line.find(".")
                SW_time = SW_line[plus_pos + 1:dot_pos] 

                minutes = int(SW_time.split(":")[0]) 
                if minutes < previous_minutes: 
                    hours = hours + 1
                previous_minutes = minutes

                timecode.write("cut_v01 %02d:%s:00 V4 black\n" % (hours,SW_time) ) 

   print "Timecode file(s) successfully created:\n %s\n\n" % (new_filename) 

for root, dirs, files in os.walk(os.getcwd()): 
SW_file=""
for filename in files:
   if (filename.startswith("Stopwatch")): 
      if (filename.endswith(".csv")): 
         convert_stopwatch(os.path.join(root, filename))
于 2013-02-14T02:27:38.347 回答