I'm currently trying to write a script to help me format simple txt of video script from sth like
1 00:00:00,000 --> 00:00:03,550 text1
2 00:00:03,550 --> 00:00:07,030 text2
to "text1 text2". I have more than 100 separate files and I am trying to write all of them together into one.
So I wrote sth like:
import re
import os
path = r'the full path of the directory'
f = open("video_script.txt", 'w')
for filename in os.listdir(path):
text = open(filename).read()
textblock = reduce(lambda x,y: x+y+' ', re.findall('([a-zA-z].*)\r', text))
newtext = textblock.replace('. ', '.\n')
f.write ('*'+filename+'*')
f.write ('\n')
f.write(newtext)
f.write('\n'*2)
f.close()
I got the code fun successfully for about 30 files then I got an error of:
TypeError: reduce() of empty sequence with no initial value
I run a separate test on that failed one and there was no error. Thanks for any help.