-2
mazen_file=open(r"C:\Users\uscs\Desktop\mazen" )
mazen_file.write("gamed nek")
mazen_file.close()

i got the following error

Traceback (most recent call last):
  File "C:\Users\uscs\PycharmProjects\pythonProject\حديد المصرين.py", line 2, in <module>
    mazen_file.write("gamed nek")
io.UnsupportedOperation: not writable

I tried to write in the file but I could not

John Gordon
  • 29,573
  • 7
  • 33
  • 58

1 Answers1

0

The r before the string has nothing to do with reading. It stands for raw string, which means python ignores special characters and thus you can use \ instead of \\. In order to open a file for writing, you need to specify the mode like this : mazen_file=open(r"C:\Users\uscs\Desktop\mazen", 'w') where w is the mode for opening the file. If you want to explore other modes, check this table.

Lior v
  • 464
  • 3
  • 12