title: Looping SQL query in python
body: <p>I am writing a python script which queries the database for a URL string. Below is my snippet.</p>
  
  <pre><code>db.execute('select sitevideobaseurl,videositestring '
            'from site, video '
            'where siteID =1 and site.SiteID=video.VideoSiteID limit 1')
  result = db.fetchall()
  
  filename = '/home/Site_info'
  output = open(filename, "w")
  for row in result:
    videosite= row[0:2]
    link = videosite[0].format(videosite[1])
    full_link = link.replace("http://","https://")
    print full_link
    output.write("%s\n"%str(full_link))
  output.close()
  </code></pre>
  
  <p>The query basically gives a URL link.It gives me baseURL from a table and the video site string from another table.</p>
  
  <pre><code>output: https://www.youtube.com/watch?v=uqcSJR_7fOc
  </code></pre>
  
  <p>SiteID is the primary key which is int and not in sequence. </p>
  
  <p>I wish to loop this sql query to pick a new siteId for every execution so that i have unique site URL everytime and write all the results to a file. </p>
  
  <pre><code>desired output: https://www.youtube.com/watch?v=uqcSJR_7fOc
                  https://www.dailymotion.com/video/hdfchsldf0f
  </code></pre>
  
  <p>There are about 1178 records.</p>
  
  <p>Thanks for your time and help in advance. </p>