0
How to take mysql column name as user input in mysql connector python?
So, I wanted to create a program where it will take input from user about everything i.e. database name, table name, table structure(column names), data and then perform various add, delete, update etc. function on it. But I am unable to take column names as user input. I tried the following code: table_structure=tuple(input('Enter the structure/row names of the table(seperated by commas):')) y.execute('create table '+name_table+''+table_structure+'') print('Table', name_table, 'created successfully') x.commit() but unfortunately it always shows errors
2 Answers
0
try this:
e="create table"+name_table+"("
table_structure=list(table_structure)
for i in range(len(table_structure)):
e=e+' '+table_structure[i]+' varchar(50),'
g=e[0:-1]
g=g+')'
y.execute(g)
x.commit()