How do I open all files in a directory in python? -


this question has answer here:

i have code

import os  def load():     filename in os.listdir("directorypath"):         content = open(filename, "r") load() 

and know how load files filename returns, @ moment error saying filenotfounderror: [errno 2] no such file or directory: 'adjectives.txt'

os.listdir() returns filename, not full path. need pass whole path open. can use os.path.join combine directory , filename:

content = open(os.path.join('directorypath', filename), 'r') 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo