I am analyzing the source of one project. Initially, the project was written in python2, but I need a code reworked for python3. The sqlite3 library is sqlite3 .

Gives an exception:

python 'sqlite3.Cursor' object has no attribute 'next'

On the following code:

 conn = sqlite3.connect(os.path.join(profile, 'data.db')) c = conn.cursor() c.execute("SELECT item1,item2 FROM metadata WHERE id = 'TEXT';") row = c.next() 

If specifically, row = c.next() .

How to replace this line?

Maybe they use the old version of the library, when the new one does it a little differently?

    1 answer 1

    The cursor is an iterator. In Python 3, the .next() method for consistency with other special methods is renamed to .__next__() use the next() built-in function :

     >>> import sqlite3 >>> db = sqlite3.connect(':memory:') >>> next(db.execute('select 1')) (1,) 

    Or more specific methods for the DB API , since the iterator is an optional extension to the DB API — sqlite3 supports, and other implementations may not support:

     >>> db.execute('select 1').fetchone() (1,)