I am writing a program to read a set of text files from folder "set" to a list.My code for this is
def get_documents():
path1 = "D:/set/"
texts = []
listing1 = os.listdir(path1)
for file in listing1:
with open(file,'r') as f:
lines = f.read().splitlines()
texts.append(lines)
But this gives me Error as
with open(file,'r') as f:
IOError: [Errno 2] No such file or directory: '0.txt'
There are text files inside D:/set/
namely 0.txt,1.txt,2.txt...
What is the reason for this Error?
Aucun commentaire:
Enregistrer un commentaire