Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeError: write() argument must be str, not tuple | writelines(l)

I wanna make a program who edit the save of a game by only editing one specific line (line 6) on a .ini file but there is an error (TypeError: write() argument must be str, not tuple save.writelines(lines) )

from tkinter import *
from tkinter import filedialog
from pathlib import Path

#  All important variables here to simplify reading my code
directory = None
path = None
save = None
room = None


def main():
      print("\n[#] Select your game directory")
      tk = Tk()
      tk.geometry("0x0")
      tk.wm_attributes('-toolwindow', 'True')      
      global directory
      directory = filedialog.askdirectory(title="Select the game directory...")
      path = Path(f"{directory}/save_data_main.ini")
      if path.is_file():  # If save file exist
          save = open(path, 'r+')
          lines = save.readlines()
          save.close()
          print("\n[*] Your currently at the", lines[5])
          print("[!] Please choose a number superior than 0 and inferior than 1000!")
          room = input("[#] Change the room value : ")
          lines[5] = "room=", str(room)
          save = open(path, 'w+')
          save.writelines(lines)
          save.close()
          print("[*] Value changed with success.")
       else:  # Error save file doesnt exist
          print("\n[!] ERROR: Save file doesn't exist! Try to create a new Game.")
          input("[*] Press Enter to continue...")
          exit()

if __name__ == '__main__':
    main()

I didnt write all the code tho, i tried to make something more simple to read and with only the important parts!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should replace the line:

lines[5] = "room=", str(room)

With:

lines[5] = "room=" + str(room)

In python the "+" operator is used to concatenate string, with the "," you are creating a tuple.

lines[5] = "room=", str(room)

is the same that:

lines[5] = ("room=", str(room))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading