我正在尝试实现一个原始字典来查找我们在实验室中使用的首字母缩略词。字典格式如下:
{'REN': 'plasma renin', 'PROP': 'procollagen III', 'IMETAB': 'intermediary metabolites, pyruvate, lactate, beta-OH-butyrate'...}
我可以在 GUI 和其他格式的字典中搜索项目,但是在尝试添加/删除项目时出现错误,但只能使用 GUI 格式。以下是两个有问题的代码片段:
此代码有效
elif inp == 'add':
abbr_in = input('acronym: ')
text_in = input('expanded text: ')
acronyms[abbr_in] = text_in
with open('acronym_dict.py','w')as outfile:
outfile.write(str(acronyms))
outfile.close()
elif inp == 'delete':
name = input("Enter acronym to delete: ").upper()
r =dict(acronyms)
del r[name]
with open('acronym_dict.py','w')as outfile:
outfile.write(str(r))
outfile.close()
和不起作用的GUI代码:
def add_acronym():
add_del_acronym.get()
add_del_acronym.upper()
abbr_in = addordel_acronym
add_expansion.get()
text_in = add_expansion
acronyms[abbr_in] = text_in
# write amended dictionary
with open('acronym_dict.py','w')as outfile:
outfile.write(str(acronyms))
outfile.close()
def remove_acronym():
name = addordel_acronym.get().upper()
name.upper()
r =dict(acronyms)
del r[name]
# write amended dictionary
with open('acronym_dict.py','w')as outfile:
outfile.write(str(r))
outfile.close()
我得到的错误是:
TypeError: get() missing 1 required positional argument: 'self'
请有人来帮助我。不明白该怎么做。谢谢