More of a question (not an issue). Raising here, since there's no Discussion section. #35
-
|
How do I delete one of the "Dialogue" events? If I try I get a "SyntaxError: invalid syntax". I'm using Python version 3.14.0 on an X86-64 system. Thanks for the attention. Cheers. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
Note that deleting items of a sequence while iterating over it may produce unexpected results, so what you might want do to is to collect the event line indices you want to delete and then perform deletion in reversed order so that the indices aren't shuffled around after each delete. indices_to_delete = []
for i, event in enumerate(doc.events):
if event.TYPE == "Dialogue":
for line in ("Remove 1", "Remove 2", "Remove 3"):
if line in event.text:
indices_to_delete.append(i)
for i in reversed(indices_to_delete):
del doc.events[i]Regarding discussions: They were actually enabled but turns out I needed to create a single discussion first in order to complete onboarding. I have done that now and moved your issue here. |
Beta Was this translation helpful? Give feedback.
-
|
That was very helpful. I followed your advice, and got it working like a charm! Thank you very much, @FichteFoll. Marking this as the answer. Btw, which library would you recommend for parsing SRTs? I zeroed in on a couple, but you might know better. |
Beta Was this translation helpful? Give feedback.
delis a keyword in Python and must be used differently. Sincedoc.eventsis a sequence you can generally delete items by index, i.e.del doc.events[i]. I did not verify whether this works, but if you don't have the index you could also usedoc.events.remove(event), which should be an alias todel doc.events[doc.events.index(event)].Note that deleting items of a sequence while iterating over it may produce unexpected results, so what you might want do to is to collect the event line indices you want to delete and then perform deletion in reversed order so that the indices aren't shuffled around after each delete.