[PATCH 09/14] python: Limit the scope of for loop counter