Python Forum

Full Version: Writing file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello everyone,
I am beginner and I am trying to write file but I am getting this type of error.
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
f=open("testfile","w")
PermissionError: [Errno 13] Permission denied: 'testfile'
As it says, it is a permissions issue, which is really an operating system issue. What folder are you trying to write to? Is testfile open in another program? What operating system are you using?
If you are using Linux, did you remember to make the file 'executable'?

chmod +x testfile
I am using win 10 and its local user. Is it necessary to run in administrator mode.
Windows requires a suffix such as .py or .exe, etc. If you just saved the file as 'testfile', Windows won't know how to open it. If you saved it as 'testfile.py', you need to specify that in line
f=open("testfile.py","w")
Also, make sure you are in the same directory as 'testfile' when you try and run it.