I was trying to add some list of words to a CSV file using python file handling, but it was giving a "PermissionError: [Errno 13] Permission denied:" error. The syntax works for a txt file. Although the file was created, no words were added to it. I tried to check the file properties and it seems okay. I don't know what else to do.
Here is the code:
words = ("Almost every creative person faces problems like procrastination").split()
words2= ("perfectionism self-doubt at one time another Even the successful ones").split()
words3 = ("But the feeling of being utterly alone on your artist’s journey insidious It").split()
words4 = ("gnaws at your confidence weakens your resolve It causes talented writers to").split()
for word in words:
word_collect= open('word_collected.csv','w+')
for word2 in words2:
word_collect = open ( 'word_collected.csv' , 'w+' )
for word3 in words3:
word_collect = open ( 'word_collected.csv' , 'w+' )
for word4 in words4:
word_collect = open ( 'word_collected.csv' , 'w+' )
word_collect.write(str(words))
word_collect.write ( "\n" )
word_collect.write ( str ( words2 ) )
word_collect.write("\n")
word_collect.write ( str ( words3 ) )
word_collect.write ( "\n" )
word_collect.write ( str ( words4 ) )
word_collect.close()
Output:
Traceback (most recent call last):
File "C:\Users\Joshua\PycharmProjects\HANGERMAN\venv\Lib\hangerman.py", line 8, in <module>
word_collect = open ( 'word_collected.csv' , 'w+' )
PermissionError: [Errno 13] Permission denied: 'word_collected.csv'