samedi 19 décembre 2020

With Python:Trying to save a Random Number in an array to MySQL database

Hi I am trying to save a Random Number to the MySQL database. I have created a database called "RandNum1" and when I try to create the Random Number as an array I get a Type Error:"'str' object is not callable" error. Here is what I have done so far:

import mysql.connector
mydb = mysql.connector.connect(
    host="localhost",
    user="root",
    passwd="",
    database="RandNum1"
)

mycursor = mydb.cursor()
import numpy as np
randnums=np.random.randint(1,20,1)

sql = "INSERT INTO RandNum (randnums) VALUES (%s)"
mycursor.execute(sql(randnums))
connection.commit()

The error is produced on this line:

mycursor.execute(sql(Randnums))

I am a newbie to Python and MySQL...any help would be appreciated.

Thanks




Aucun commentaire:

Enregistrer un commentaire