from Input/Output 1/9, you are to just click run and see the script.py 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\file.py, 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”)
f.close()
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”)
file.close()