Skip to content
Discussion options

You must be logged in to vote

del is a keyword in Python and must be used differently. Since doc.events is 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 use doc.events.remove(event), which should be an alias to del 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.

indices_to_delete = []
for i, event in enumerate(doc.events):
    if event.T…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by jay-ramani
Comment options

You must be logged in to vote
2 replies
@FichteFoll
Comment options

@jay-ramani
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #33 on December 02, 2025 10:34.