I'm trying to get a random word file from a specified directory, but it returns nothing Here's the some part of the code.
for filename in glob.glob(os.path.join(path, '*docx')):
fl = []
fl.append(filename)
return fl
choice = random.choice(fl)
doc = docx.Document(choice)
print(doc.paragraphs[0].text) # There is a paragraph on the document starting on the first line so problem is not there.
There is nothing wrong with the path. Eveything was working just fine when I was not trying to get only one random file instead of all the files.
- What am I doing it wrong?
- Is there any more efficient way of doing it?
Aucun commentaire:
Enregistrer un commentaire