SQLite Forum

reading multiple lines from multiple sources...
Login
The reason you get the last line of each file is that is exactly what your code is doing, without the break, it's processing each file in turn, then after it's done processing each file, it inserts a row into your database table.  You then repeat the process 9 times.

If you want to operate on each line of the file in turn, you'll need to open them up, and enumerate through all of the files in lockstep.  There are several ways to do this, one such way is to use the built in Python operator `zip` to work through the enumeration of each file for you:

```
#!/usr/bin/env python3

import sqlite3

def printthis():
    db = sqlite3.connect("example.db")
    db.execute("CREATE TABLE IF NOT EXISTS datasamples(names, colors, shapes, favfood);")
    sql = 'INSERT INTO datasamples(names, colors, shapes, favfood) VALUES(?,?,?,?)'
    print("Connected to SQLite")

    with open("names.txt") as f1, open("colors.txt") as f2, open("shapes.txt") as f3, open("favfood.txt") as f4:
        for name, color, shapes, favfood in zip(f1, f2, f3, f4):
            db.execute(sql, (name.strip(), color.strip(), shapes.strip(), favfood.strip()))
    db.commit()

    print("-- results --")
    for row in db.execute("SELECT * from datasamples;"):
        print(", ".join(row))

if __name__ == "__main__":
    printthis()
```

And as a side note:  While I've answered the question for you, and fixed a bug in your SQL (you had one too many `?` for the bound parameters, really your question had nothing to do with SQLite.  You'll probably get much better help with Python specific issues on a forum for Python issues.