pysrt
pysrt copied to clipboard
Make SrtFile Iterable
>>> for k,v in enumerate(subs):
... print(v.text)
...
blahblah
blahblah
blahblah
...
Sorry but I don't understand:
SrtFileis already an iterable__getitem__is not to implement iteration, but for index based access of a sub element__getitem__is already implemented by the parent class (UserList).
What am I missing?
It is quite weird that you can write something like
for i in srtfile:
But not
for k, v in enumerate(srtfile)
This quick patch will fix this problem.
2016年9月14日星期三,Jean Boussier [email protected] 写道:
Sorry but I don't understand:
- SrtFile is already an iterable
- getitem is not to implement iteration, but for index based access of a sub element
- getitem is already implemented by the parent class (UserList).
What am I missing?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/byroot/pysrt/pull/63#issuecomment-246924353, or mute the thread https://github.com/notifications/unsubscribe-auth/ABfRgt4eaNqJFCW4pc3n_8nwb_K_D1Tmks5qp5xagaJpZM4J8Wk4 .
You absolutely can use enumerate:
- https://github.com/byroot/pysrt/commit/18af0545ef8f8a069bf35133dbe92379b713cebb
- https://travis-ci.org/byroot/pysrt/builds/159892827
Not sure what your problem is, but it's not this.