Correct way to loop through List from Python
#1
After triggering ActivateWindow for a tv show which shows the list of episodes I would like the focus to be set on a specific episode in the list.

From python script what is the correct way of looping through a list of episodes?

Using other snippets on this forum I'm experimenting with a while loop along the lines of below but it doesn't work - it is not moving the focus and therefore return the same DBID value. It feels wrong, I'm sure there would be an easier and cleaner way to loop through a list of episodes?

python:
list_idx = 0
xbmc.executebuiltin("Control.SetFocus({}, {}, absolute)".format(cid, list_idx))
found_episode = False
while not found_episode:
   this_episodeid = int(xbmc.getInfoLabel('ListItem.DBID'))
   if this_episodeid != selected_episode_dbid:
      list_idx += 1
      xbmc.executebuiltin("Control.SetFocus({}, {}, absolute)".format(cid, list_idx))
   else:
      found_episode = True
Reply

Logout Mark Read Team Forum Stats Members Help
Correct way to loop through List from Python0