Permission denied: 'output.txt'

from Input/Output 1/9, you are to just click run and see the write into output.txt
I tried to replicate this into Notepad ++ so I could reference later when I may need to know how to do this but it gave me an error.

Traceback (most recent call last):
File "C:\python27\, line 6, in
f = open(“output.txt”, “w”)
IOErrror: [Errno 13] Permission denied: ‘output.txt’

my code looks this this:

#this will write a file called “output.txt”

my_list = [i ** 2 for i in range(1, 11)]

Generates a list of squares of the numbers 1 - 10

f = open(“output.txt”, “w”)

for item in my_list:
f.write(str(item) + “\n”)


and I even created a file called output.txt in the same folder so that it could possibly work and write into it. It works on the Code academy, but not on notepad ++, what am I doing wrong here?

Additional information:

if I write a code like this, (something I found on a different website on how to write a file from a different file with python) and it works, should I just only do it this way? This is the code that does work on notepad++

text = [“line 1”,“line 2”,“line 3”, “line 4”,“line 5”]
file = open(“C:\Users\Riiver\Desktop\Python\newfile.txt”, “w”)
for i in text:
file.write(str(i) + “\n”)

There’s nothing wrong about using the current directory, but the way you’re executing python makes that location be somewhere where you don’t have write permission

What would make more sense is to open a command prompt, navigate to the directory where you want the file, and run python from there - or by some other means run python in an appropriate directory

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.