Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

How to write long python mysql statements?

Is this a correct format for writing correct python mysql statements;

    for row in rows:
        insert_into_track_table_query = """INSERT INTO track_table 
        (
        track_title, 
        track_desc, 
        track_link, 
        track_date, 
        track_img_link, 
        track_source, 
        track_pri_date_time, 
        track_series
        ) VALUES (
        %s,
        %s,
        %s,
        %s,
        %s,
        %s,
        %s,
        %s
        )"""

        cursor.execute(insert_into_track_table_query,\
              (row['pri_title'],
               textarea, 
               row['pri_link'],
               row['pri_date'],
               row['pri_img_link'],
               row['pri_source'],
               trackTime,
               row['pri_series'])
              ,)
        conn.commit()

I am talking in terms of layout and such

1 Answer

I have a feeling that there's missing something in that code.

Quick question: Why not use peewee when working with MySQL and python? It makes working with databases so much easier :-)

https://teamtreehouse.com/library/using-databases-in-python