User:Emily/Prototyping/Trimester 03/02
with open("state.en.srt") as f:
lines = f.readlines()
times_texts = []
current_times , current_text = None, ""
for line in lines:
times = re.findall("[0-9]*:[0-9]*:[0-9]*,[0-9]*", line)
if times != []:
current_times = map(convert_time, times)
elif line == '\n':
times_texts.append((current_times, current_text))
current_times, current_text = None, ""
elif current_times is not None:
current_text = current_text + line.replace("\n"," ")
return times_texts
</source lang=python>
apply above script to multiple files add below on top -> def (defining functions of your own) -> def function_name():
<source>
def readsrt(srtpath):
with open(srtpath, "rU") as f:
lines = f.readlines()
sys.argv command line arguments -> passed to a python script
argv[0] is the script name
pat = sys.argv[1] #the pattern I search
time = 0
for p in sys.argv[2:]: #the srt files I search in
print p
tt=readsrt(p)