Maksims Kazoha
Maksims Kazoha

Reputation: 1

PermissionError: [Errno 13] Permission denied: "text_file"

Im getting this error :

  File "C:/Users/Admin/PycharmProjects/project/Project.py", line 207, in record_attendance
    with open("SOFT_6017.txt", "w") as module_1:
PermissionError: [Errno 13] Permission denied: 'SOFT_6017.txt'

I've searched all over the web and wasn't able to find an answer to my solution. i asked a phew people and they didn't know what to do with it. So they suggested to me to write a question here.

Content of SOFT_6017:

Mary Martin,10,0,0
Alan Wilson,0,9,1
Alan Lowe,5,6,0

Where im trying to add that details:

   with open("SOFT_6017.txt", "w") as module_1:
        soft_6017_1 = module_1.readline().split(',')
        soft_6017_2 = module_1.readline().split(',')
        soft_6017_3 = module_1.readline().split(',')

        name_1_1 = soft_6017_1[0]
        attended_1_1 = int(soft_6017_1[1])
        missed_1_1 = int(soft_6017_1[2])
        excused_1_1 = int(soft_6017_1[3])

        name_2_1 = soft_6017_2[0]
        attended_2_1 = int(soft_6017_2[1])
        missed_2_1 = int(soft_6017_2[2])
        excused_2_1 = int(soft_6017_2[3])

        name_3_1 = soft_6017_3[0]
        attended_3_1 = int(soft_6017_3[1])
        missed_3_1 = int(soft_6017_3[2])
        excused_3_1 = int(soft_6017_3[3])

        count_1 = len(open("SOFT_6017.txt").readlines())

        data = f"{name_1_1}, {attended_1_1}, {missed_1_1}, {excused_1_1} \n " \
               f"{name_2_1}, {attended_2_1}, {missed_2_1}, {excused_2_1} \n " \
               f"{name_3_1}, {attended_3_1}, {missed_3_1}, {excused_3_1}"

        module_1.seek(0)
        module_1.write(data)

Line 207 - with open("SOFT_6017.txt", "w") as module_1: this line.

Upvotes: 0

Views: 1165

Answers (2)

Devansh Soni
Devansh Soni

Reputation: 771

You are trying to read the file which you have opened in write mode. Change this

with open("SOFT_6017.txt", "w") as module_1:

To this

with open("SOFT_6017.txt", "r") as module_1:

And to write data to the file, remove this line:

module_1.write(data)

and open another with block:

with open("SOFT_6017.txt", "w") as mod_wr:
    mod_wr.write(data)

Hope this helps :)

Upvotes: 1

Sho_Lee
Sho_Lee

Reputation: 149

It's because you can have open your archive "SOFT_6017.txt", try to close it and try again.

Upvotes: 0

Related Questions