Python Forum
Thread Rating:
  • 3 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Writing file
#1
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'
Reply
#2
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?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
If you are using Linux, did you remember to make the file 'executable'?

chmod +x testfile
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#4
I am using win 10 and its local user. Is it necessary to run in administrator mode.
Reply
#5
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.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question [SOLVED] Linefeed when writing "f" strings to text file? Winfried 5 859 Nov-04-2025, 11:51 AM
Last Post: buran
  .xlsm file can't be opened after writing data to one worksheet mhyatt 4 887 Oct-11-2025, 11:25 PM
Last Post: Pedroski55
  Problems writing a large text file in python Vilius 4 2,035 Dec-21-2024, 09:20 AM
Last Post: Pedroski55
  writing list to csv file problem jacksfrustration 5 4,141 Jul-04-2024, 08:15 PM
Last Post: deanhystad
  Writing string to file results in one character per line RB76SFJPsJJDu3bMnwYM 4 5,736 Sep-27-2022, 01:38 PM
Last Post: buran
  Writing to json file ebolisa 1 2,245 Jul-17-2022, 04:51 PM
Last Post: deanhystad
  Writing to External File DaveG 9 5,863 Mar-30-2022, 06:25 AM
Last Post: bowlofred
  Writing to file ends incorrectly project_science 4 4,707 Jan-06-2021, 06:39 PM
Last Post: bowlofred
  Writing unit test results into a text file ateestructural 3 8,184 Nov-15-2020, 05:41 PM
Last Post: ateestructural
  Writing to file in a specific folder evapa8f 5 5,790 Nov-13-2020, 10:10 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020