'(WinError 32) The process cannot access the file because it is being used by another process: 'data.csv' -> 'data.csv.bak'
I know there are several questions that are the same as mine but even by referring to them, I can't seem to solve the error. Whenever I "open" the csv file, I always use with xxx as xx: which is supposed to prevent this error but I am unsure why I still face this error.
The goal of this code is to update a single value in the "EP" column of the csv file given the specific "uname".
According to the debugger, this is the problematic code print(",".join(re.fieldnames)) and this is the context of the code:
np = input("Input new electricity unit price")
with fileinput.input(files=('data.csv'), inplace=True, mode='r') as g:
re = csv.DictReader(g)
print(",".join(re.fieldnames)) # ERROR CAUSED BY THIS LINE
for x in re:
if row["Uname"] == uname:
row["Ep"] = np
print(",".join([row["Uname"],row["Pw"], row["Ep"]]))
I am only showing an extraction of the entire function because I am afraid of being striked for plagiarism. Please let me know if more codes are necessary. Thank you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
