Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. import os
  2.  
  3. class Corpus:
  4.     def __init__(self,fp):
  5.         self.fp = fp
  6.     def emails(self):
  7.         code = ['utf-8', 'windows-1252', 'iso-8859-1']
  8.         newDir = os.path.join(os.getcwd(),self.fp)
  9.         filelist = os.listdir(newDir)
  10.         for fname in filelist:
  11.             if '!' not in fname and os.path.isdir(fname) == False:
  12.                 for coding in code:
  13.                     try:
  14.                         with open(newDir + '/' + fname, "r", encoding=coding) as body:
  15.                             yield fname, body.read()
  16.                         break
  17.                     except:
  18.                         continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement