-1

I am creating a questionnare web application with html and python using flask. Currently, the html form inputs are saved to a CSV file, and the questionnare results are calculated with python code, by reading the csv file.

When the users answers are being saved to the CSV, I want to assign a "user response id" that indicates the response of a SPECIFIC user, so that when the questionnare results are calculated, they're calculated for this particular user. I am not sure how to do this. How do I assign an ID value for a user, for all their answers?

Here is how the responses to the questionnare are saved:

ID,Response_ID,Question_ID,Ans
1,2,1,1985
2,2,2,6
3,2,3,3000
4,2,4,2

So these would be the responses from user "2". Thank you.

user3611
  • 151
  • 2
  • 9

1 Answers1

0

Create a global variable and increase it every time your function to save gets invoked.

counter = 1

def my_saving_function():
   #do something to add the counter variable into the data to be written to the CSV.
   counter++

If you're going to implement something like an SQL database to your app, you can just create an autoincrement integer column, then query it with something like MAX(ID_COLUMN) and add that to the CSV you're about to write.

Dasph
  • 420
  • 2
  • 15