From 7cfd9a08d6aa06d78ccfdc69152abe4537fa2f10 Mon Sep 17 00:00:00 2001 From: cclauss Date: Wed, 27 Sep 2017 06:34:54 +0200 Subject: [PATCH] =?UTF-8?q?file()=20was=20removed=20from=20Py3,=20use=20?= =?UTF-8?q?=E2=80=98with=20open()=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit file() no longer exists in Python 3. The current version does not explicitly close file handles but this version fixes that. --- exts/smallseg.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/exts/smallseg.py b/exts/smallseg.py index 28a35de..ad96da2 100644 --- a/exts/smallseg.py +++ b/exts/smallseg.py @@ -16,8 +16,10 @@ class SEG(object): curpath=_curpath self.d = {} print("loading dict...", file=sys.stderr) - self.set([x.rstrip() for x in file(os.path.join(curpath,"main.dic")) ]) - self.specialwords= set([x.rstrip().decode('utf-8') for x in file(os.path.join(curpath,"suffix.dic"))]) + with open(os.path.join(curpath, "main.dic")) as in_file: + self.set([x.rstrip() for x in in_file]) + with open(os.path.join(curpath,"suffix.dic")) as in_file: + self.specialwords= set([x.rstrip().decode('utf-8') for x in in_file]) print('dict ok.', file=sys.stderr) #set dictionary(a list) def set(self,keywords):