Errno13, Permission denied when trying to read file

We're All Mad Here picture We're All Mad Here · Dec 27, 2015 · Viewed 14.2k times · Source

I have created a small python script. With that I am trying to read a txt file but my access is denied resolving to an no.13 error, here is my code:

import time
import os

destPath = 'C:\Users\PC\Desktop\New folder(13)'
for root, dirs, files in os.walk(destPath):

f=open(destPath, 'r')
.....

Answer

Gary van der Merwe picture Gary van der Merwe · Dec 27, 2015

Based on the name, I'm guessing that destPath is a directory, not a file. You can do a os.walk or a os.listdir on the directory, but you can't open it for reading. You can only call open on a file.

Maybe you meant to call open on one or more of the items from files