I have been trying to overwrite a file as i do not need it in my folder as it makes a duplicate. I have used different Syntax such as os.rename but it does not work with my code. So I then used os.replace but now i get a message saying 'PermissionError: [WinError 5] Access is denied'. If anyone can help, please help as soon as possible.
This is the code that I've been trying to fix:
if row[0]==user:
with open('temp','a')as newone:
theaverage = (int(counter) + int(row[1]) + int(row[2]))/3
high = max(int(counter), int(row[1]),int(row[2]))
newone.write("%s,%s,%s,%s,%s,%s\n"%(user,counter,row[1],row[2],theaverage,high))
newone.close()
else:
with open('temp','a')as newone:
newone.write("%s,%s,%s,%s,%s,%s\n"%(row[0],row[1],row[2],row[3],row[4],row[5]))
newone.close()
os.replace('temp','Class A.csv')
Here is the Error message I'm getting:
1 (1).py", line 113, in part2
os.replace('temp','Class A.csv')
PermissionError: [WinError 5] Access is denied: 'temp' -> 'Class A.csv'