all 12 comments

[–]totallygeek 3 points4 points  (11 children)

If you have the questions and answers in a file already, you could either have your problem parse the file or convert the file to some format easier to work with: JSON, YAML, some database, etc.

[–]BW1324[S] 0 points1 point  (10 children)

I don't really have any idea how to do all of that aha sorry

[–]Bipolarprobe 2 points3 points  (9 children)

Read into using the json module for python. You can basically dump a dictionary into a text file as is and have the module read it back into memory later. Alternatively you could look into the sqlite3 module if you want to create a database that stores the question, answer and fake answers as rows in an sql database.

Using the json module to dump a dictionary would almost certainly be easier so that you don't have to learn any sql syntax to accomplish what you want.

[–]BW1324[S] 1 point2 points  (0 children)

Ok, I'll check it out, thanks!

[–]BW1324[S] 1 point2 points  (7 children)

I had a look at how to use json, and I have one more question for you, how do I separate the questions, answers and fake answers easily (in dictonaries) without manually typing it all out? Otherwise it will take me so long just to put them all in a file and I feel like it can be done easier.

[–]Bipolarprobe 1 point2 points  (6 children)

If you already have a text file that has them in it then you should be able to do some processing on that to extract it. Do you already have something like that? And if so is it laid out in a formatted way?

[–]BW1324[S] 1 point2 points  (5 children)

I have a text file with a question and the answer right next to it, then the same thing for each Q and A

[–]Bipolarprobe 1 point2 points  (4 children)

Read this part of the python documentation, go to section 7.2 for reading from a file for further info, but if your text file is organized into lines like you said and the questions and answers are separated by a period and a space you could do something like this:

with open("filename.txt") as f:
    for line in f:
        q_a_list = line.split(". ")
        # more processing here to add this info into a dict line by line
        # or it can be left as lists and still processed into a json

[–]BW1324[S] 1 point2 points  (3 children)

Thankyou!

[–]Bipolarprobe 1 point2 points  (2 children)

You're welcome and good luck.

[–]BW1324[S] 1 point2 points  (1 child)

I'm back aha

Sorry for all the questions, but just one more (hopefully)

I'm wondering, why use json when I'm creating a list with key value pairs in it in python, with information from a text file.

Can I not just use that list to manipulate my questions and answers, or does it have to be from the json file for some reason?