SQLite Forum

reading multiple lines from multiple sources...
Login
Hello all!

I'm having issues with reading multiple lines from multiple sources (txt files)  into rows. Below is code.. If I use the commented out break, I get the first line of each file into its appropriate row as desired, but no further as intended purpose of break... If I don't use break, I get the last line of each file. How can I get each line printed to the database?

I'm pulling 10 rows from 5 different text files at the moment. 


text files are simple data, below is an example


*names*
tom
dan
paul

*colors*
blue
red
orange

*shapes*
circle
box
rectangle

*favfood*
pizza
taco
burger



here is my code...


def printthis():
    db_elements = 'INSERT INTO datasamples(names, colors, shapes, favfood) VALUES(?,?,?,?,?)'
    print("Connected to SQLite")

    i = 0
    while i <= 9:
        with open(f1) as j:
            for line in j:
                line1 = line
                # break
        with open(f2) as q:
            for line in q:
                line2 = line
                # break
        with open(f3) as w:
            for line in w:
                line3 = line
                # break
        with open(f4) as u:
            for line in u:
                line4 = line
                # break
        with open(f5) as k:
            for line in k:
                line5 = line
                # break
        curs.execute(db_elements, (line1, line2, line3, line4, line5))
        i += 1



I know there probably is a simpler way to achieve what I am going for, I'm just running into walls.

Thanks!