我想要一个带有所有文本的文本文件,它在程序中表示,以便将我的程序翻译成另一种语言。我可以使用普通列表,但是当查看代码时很难看到哪些文本将被表示。将文件转换为字典
文本文件:
here is the text represented in the running program
inside the code you cant say whats written right here
代码:
language_file = open("file.txt", "r", encoding="utf-8")
language_list = storage_file.readlines()
print(language_list[1])
我希望你能理解与^ 而不是使用一个列表的我的问题,我想用一本字典。而该文件,那么应该是这个样子:
"some_shortcut_to_remind_me_whats_happening": "Text in another language"
"another_shortcut": "Now I know whats written right here"
的代码,然后可能看起来像这样:
print(language_dict["another_shortcut"])
但我不知道怎么去解释了文本文件的
你想第一行作为关键和第二行作为值等? –
可能的重复:https://stackoverflow.com/questions/4803999/python-file-to-dictionary – mimre