Ad
Is It Possible To Write A Python List Into A Database With Pymssql?
I am tyring to write a python list via pymssql into a database table. I am aiming to write each list entry into a different row of the same column.
When trying this I am getting the error:
ValueError: 'params' arg () can be only a tuple or a dictionary.
Is there a way with pymssql or should I use something else?
My code:
from bs4 import BeautifulSoup as bs
import re
import pandas as pd
from collections.abc import Iterable
import pymssql
conn = pymssql.connect(
host='x',
port=x,
user='x',
password='x',
database='x'
)
cursor = conn.cursor()
cursor.execute('SELECT x FROM x')
text = cursor.fetchall()
conn.close()
raw = []
raw.append(text)
raw1 = str(raw)
soup = bs(raw1, 'html.parser')
autor = soup.get_text()
clear = []
s = autor.replace('\\n', '')
clear.append(s)
conn = pymssql.connect(
host='x',
port=x,
user='x',
password='x',
database='x'
)
cursor = conn.cursor()
cursor.execute('INSERT INTO mytablename (columnname) VALUES (?);', [','.join(clear)])
conn.close()
Ad
Answer
You can use executemany:
cursor.executemany('INSERT INTO mytablename (columnname) VALUES (%s);', clear)
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad