byroot / pysrt

Python parser for SubRip (srt) files
GNU General Public License v3.0
446 stars 67 forks source link

Make SrtFile Iterable #63

Open cnbeining opened 7 years ago

cnbeining commented 7 years ago
>>> for k,v in enumerate(subs):
...     print(v.text)
... 
blahblah
blahblah
blahblah
...
byroot commented 7 years ago

Sorry but I don't understand:

What am I missing?

cnbeining commented 7 years ago

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 notifications@github.com 写道:

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 .

byroot commented 7 years ago

You absolutely can use enumerate:

Not sure what your problem is, but it's not this.