How to take mysql column name as user input in mysql connector python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

20th Feb 2022, 9:43 AM
Rishabh Gusain
Rishabh Gusain - avatar
1 Answer
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()
18th Feb 2024, 5:46 PM
rsj