Answer the question
In order to leave comments, you need to log in
How to query mysql in python3.5?
The problem is this. I am getting json string with data.
I transform it data= json.loads(response)
I need to interpose these data into a mysql DB.
I'm trying to insert 20 rows in one request.
INSERT INTO table_name (col1, col2, ... col20)
VALUES (...), (...), ...
",".join(...)
Answer the question
In order to leave comments, you need to log in
I solved my problem using MySQLdb.
1. Parsed the json file into a two-dimensional list
2. Formed a query string
query = "INSERT INTO ads_irr_ru_content (col1, col2, .... ,col5) VALUES " +
",".join("(%s,%s,%s,%s,%s)" for _ in values)
cur.execute(query, flattened_values)
I'll make out already then instead of comments =)
there are a lot of libraries, but from the last one for working with the database I liked
1. records , its author Kenneth Reitz, the author of the requests library.
2. peewee the second well-known small and somewhat similar to django ORM or Alchemy
sql = ('''INSERT INTO users (login, password) VALUES (%s, %s)''')
data = (login, password)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question