Note that there are some explanatory texts on larger screens.

plurals
  1. POPython - for loop exits 'prematurely'
    primarykey
    data
    text
    <p>EDIT: ANSWER: I needed to create another cursor for the 'einlesen()' function.</p> <p>This is my first time using SQLite3 in Python, so excuse my (maybe) horrible syntax ;) I'm trying to build kind of a DVD-Database, which fetches necessary information (actors etc.) directly from amazon. The whole program is based upon SQLite3 and Python 2.7.</p> <p>Everything works well, except my plannes "update" feature.</p> <pre><code>def update(): print 'Update Datenbank....bitte warten....' cursor.execute('''SELECT titel, amazon, erhalten, ausgeliehen FROM movies''') antwort = 'update' for row in cursor: stelle = row[1] ausg = row[2] erh = row[3] einlesen(stelle, ausg, erh, antwort) print row[0] raw_input('Update komplett!') menu() </code></pre> <p>The problem is, the loop exits after one iteration.</p> <p>The output looks like this:</p> <pre><code>Update Datenbank....bitte warten.... #a few seconds pass The Day After Tommorrow Update komplett! </code></pre> <p>So I see, the loop and the function call are correct (the database gets updated correctly - done by the function 'einlesen()'), but there are more iterations, not just one... So my question is: What is wrong? ;)</p> <p>Here is the (abbreviated) 'einlesen()' function:</p> <pre><code>def einlesen(asin, ausg, erh, antwort): d = {} infos = urllib.urlopen('http://www.amazon.de/dp/'+asin).read() titel = infos[infos.find('Kaufen Sie')+11:infos.find('nstig ein')-3] art = 'dvd' infos = remove_html_tags(infos) infos = infos[infos.find('Darsteller: '):infos.find('Durchschnittliche')] infos = infos.split('\n') for x in range(200): try: infos.remove('') except: break for element in infos: d[element.split(': ')[0].lstrip()] = element.split(': ')[1] #(excluded the whole Info-Scraping process) if antwort == 'update': movie = dauer, art, regie, jahr, fsk, darsteller, titel sql = ('''UPDATE movies SET laufzeit = ?, art = ?, regie = ?, jahr = ?, fsk = ?, darsteller = ? WHERE titel = ?''') cursor.execute(sql, movie) connection.commit() else: menu() </code></pre> <p>Thanks for your help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload