for loop with variable

Post your questions, doubts and issues related to Python Programming
no avatar
Posts: 1
Joined: Sat Apr 27, 2013 8:26 am

for loop with variable

by kajti90 » Sat Apr 27, 2013 8:40 am

Hi, I don't have much programing experience (I don't have any tbh) but I need to write python code which will show youtube videos searched with specific keywords.
So far I managed to write a code which shows results (not really; it shows just titles) of one search. I would like to change it so it shows results of 20 different searches. I know it can be done with use of for loop but I tried and cannot achieve anything. Basically I want to run the code with variable "instruments" changing each time to different word from the list.

list of the words for "instrument" variable: guitar, mandolin, piano, bazouki, ukulele, bones, sintar, oud, pipa, clarinet, rebab, lute, fiddle, santoor, lyre, tres, tambura, koto, harp, shamisen

that is what I have so far:

Code: Select all

instrument = "Guitar"
secpart = "performance"

yt_service =
query =
query.vq = instrument + secpart
query.max_results = 2
query.orderby = 'viewCount'
query.racy = 'include'
feed = yt_service.YouTubeQuery(query)

for entry in feed.entry:
  print entry.title.text

+ if anyone knows how to change it from showing only titles to showing actuall videos I would be more than grateful!

Return to Python Programming