I am attempting to create a function that I can call with a column name and have it return the contents of the column from a table (tablename is in the code).
I am past the point of errors but cannot get it to return the values in the column, instead it returns a list filled with the column name that is as long as the fields in the column.
def retrieve_data_game(column):
with sqlite3.connect("gamereview.db") as db:
cursor = db.cursor()
cursor.execute ("select ? from game",[column])
output= cursor.fetchall()
db.commit()
return output
calling this with:
if __name__ == "__main__":
a="gameID"
gameID = retrieve_data_game(a)
print(gameID)
this print statement will return:
[('gameID',), ('gameID',), ('gameID',), ('gameID',)]
any help would be greatly appreciated kind regards
>and*in the code? Likely you should edit the post and remove them. Indent the code with 4 leading spaces to separate it from the rest of the question.cursor.execute ("select ? from game",[column]), why putcolumninto the brackets?executeexpects an array and indexes the string if you don't pass in an array/tuple?notation isn't acceptable for identifier locations. That doesn't explain what the given substitution is actually doing, but it might help you move forward...