-4

テキストファイルをpython辞書に保存し、テキストファイルに変更を加えています。

私が直面している問題は、辞書の内容をテキスト ファイルに更新することです。

テキストファイルを読み取るコード:

    with open ('wvtc_data.txt','r')as x:
      for line in x:
            line = line.rstrip ('\n')
            items = line.split (':')
            key,value = items[0], items[1:]
            main_dic[key] = value
            choice=0
            while choice != QUIT:
                  choice = get_menu_choice()
                  if choice==DISPLAY:
                      display(main_dic)
                  elif choice==CHANGE:
                      change(main_dic)
                  elif choice== REMOVE:
                      remove (main_dic)
                  elif choice==WRITE:
                      write(main_dic)

辞書に加えられた変更でテキスト ファイルを更新するには、書き込み関数 (最後の関数) が必要です。助けてください!

4

1 に答える 1