PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'students.txt' -> 'students.txt.bak' code example

Example 1: PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'students.txt' -> 'students.txt.bak'

I also ran into this error because,
I was opening the file whe it was already open
make sure that you are doing it right

Example 2: PermissionError: [WinError 32] The process cannot access the file because it is being used by another process:

import shutil
            # U must delete config folder every run
            shutil.rmtree('config')  # Delete config folder