I just finished a Python course and I'm working on my very first project, a tool for practising Spanish verbs and their conjugations. The tool is working, but now I want to improve it. For example, it's currently difficult to handle the data (e.g. add past tense to a verb + complicated random quiz function).
I however stumbled upon a couple of problems, one of them being: how can I add a new dictionary and give that dictionary the name from raw input? I thought that shouldn't be hard, but haven't found a solution after a lot of searching.
I have two files: one with the code and a .txt file that contains all verbs as dictionaries on seperate lines. Below you see my function for adding a new verb and appending it to the .txt file.
Example of a line in my .txt file:
to talk = {'present': ['hablo', 'hablas', ... ]}
Current code:
def add_verb():
verb = {}
name = (raw_input("Verb in Dutch: "))
tense = (raw_input("Verb tense: "))
conjugations = []
conjugations.append(raw_input("Yo: "))
conjugations.append(raw_input("Tú: "))
verb_dict[tense] = conjugations
with open("verbs.txt", "a") as abc:
abc.write("%s = {'%s': %s}\n" % (name, tense, conjugations))
Basically, what I want is this:
abc.write(dictionary)
Thus, I want the dictionary to be written into the file as it is, but with the name of the dictionary given by raw input.
I'm currently also thinking of using a Verb class, because I think that would make the tool even better, but then I stumbled upon the exact same problem (how do I give a new class instance a name that's given by raw input?).
P.S. If you see other things that I should improve, please don't hesitate to mention this.