How do i use table data from my sqlite3 database as a python variable
Question: My code so far

    
    
    conn = sqlite3.connect('databaserm/database')      
    curs = conn.cursor()         
    curs.execute('SELECT * FROM saves')     
    lvl = curs.fetchone()    
    conn.close()
    

ok maybes its the code i used to add the data to the db

i've tried this

    
    
    cn = sqlite3.connect(/databaserm/database")
    curs = cn.cursor()
    curs.execute('DROP TABLE saves')
    curs.execute('CREATE TABLE saves (lvl)')
    #curs.execute('INSERT INTO saves VALUES (null, ?)', lvl)
    
    query = """INSERT INTO saves (lvl)
                    VALUES (?)"""
    data =  [lvl]
    
    curs.execute(query, data)
    
    cn.commit
    cn.close()
    

and this

    
    
    conn = sqlite3.connect('/databaserm/database')
    curs = conn.cursor()
    curs.execute('INSERT INTO saves VALUES(null, ?,)', (lvl,))
    conn.commit
    


Answer: Executing `select` and then `fetchone` will return a tuple. What else do you
need?

Here's an example:

    
    
    import sqlite3 as sqlite
    
    con = sqlite.connect(':memory:')
    cursor = con.cursor()
    
    cursor.execute('''
        create table names (id integer primary key,
                            name varchar(50), email varchar(50))''')
    
    cursor.execute('''
        insert into names values (null, "John Doe", "jdoe@jdoe.zz")''')
    cursor.execute('''
        insert into names values (null, "Mary Sue", "msue@msue.yy")''')
    
    name = """Lu'k'e d"fdf" Sma"""
    email = "use@force.net"
    
    cursor.execute(
        '''insert into names values (null, ?, ?)''',
        (name, email))
    
    cursor.execute('select * from names')
    
    for c in cursor:
        print c
    

Uses iteration over `cursor` (an alternative way to get result). Prints:

    
    
    (1, u'John Doe', u'jdoe@jdoe.zz')
    (2, u'Mary Sue', u'msue@msue.yy')
    (3, u'Lu\'k\'e d"fdf" Sma', u'use@force.net')
    

Using `fetchone` instead of iteration:

    
    
    print cursor.fetchone()
    cursor.close()
    

Prints:

    
    
    (1, u'John Doe', u'jdoe@jdoe.zz')
    

