私は変数に渡すことができる関数を記述しようとしていますが、この変数は何とかMYSQL文に渡すことができます。Python with MYSQL
私はテーブルに値を追加する必要がありますが、テーブルに名前を付けるために変数を使用するときは機能しません。
下記のコードの一部を確認してください:
感謝 K
def __init__(self):
self.connection = pymysql.connect(host='localhost',
user='root',
password='Mandy123',
db='connectiontest',
cursorclass=pymysql.cursors.DictCursor)
self.mycursor = self.connection.cursor()
def create_table(self, name):
sql = (
"CREATE TABLE IF NOT EXISTS (%S) "
"(id int auto_increment primary key, date date, "
" open float, high float, low float, close float, "
" volume float)"
)
self.mycursor.execute(sql)
self.connection.commit()
name= input('what is the sql table name ? ')
db= sql_manager()
db.create_table(name)
変数 'name'はどこのSQL文にも入れません。また、ユーザが 'name'のために置くものに注意してください。 – dstudeba