How can I change this python code to ignore Mac OS' .DS_Store files?
class MySentences(object):
def __init__(self, dirname):
self.dirname = dirname
def __iter__(self):
for fname in os.listdir(self.dirname):
for line in open(os.path.join(self.dirname, fname)):
yield line.split()
Edit: This question looks a lot like this question (How to ignore hidden files using os.listdir()?) but I don't know how to implement that solution into the above class. I tried this:
class MySentences(object):
def __init__(self, dirname):
self.dirname = dirname
def __iter__(self):
for fname in os.listdir(self.dirname) if not fname.startswith('.'):
for line in open(os.path.join(self.dirname, fname)):
yield line.split()
But it didn't work.