Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- class Corpus:
- def __init__(self,fp):
- self.fp = fp
- def emails(self):
- code = ['utf-8', 'windows-1252', 'iso-8859-1']
- newDir = os.path.join(os.getcwd(),self.fp)
- filelist = os.listdir(newDir)
- for fname in filelist:
- if '!' not in fname and os.path.isdir(fname) == False:
- for coding in code:
- try:
- with open(newDir + '/' + fname, "r", encoding=coding) as body:
- yield fname, body.read()
- break
- except:
- continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement