Is there a way in python to constrain an argument of a function to be only a set of values, the user should type the name of the column to change:
import sqlite3
def update_table(self, id: int, column_name: str, value: str):
conn = sqlite3.connect("myDatabase.db")
c = conn.cursor()
c.execute("UPDATE table SET " + column_name + " = " + value +
" WHERE id=" + id + ";")
c.commit()
c.close()
id = input("Type the id: ")
c_name = input("Type the column name: ")
value = input("Type the new value: ")
update_table(id, c_name, value)
The problem is if the user type the name of a column that doesn't exist the code will break. What is the best way to constrain this choice?