Skip to content

Commit 7cfd9a0

Browse files
author
cclauss
authored
file() was removed from Py3, use ‘with open()’
file() no longer exists in Python 3. The current version does not explicitly close file handles but this version fixes that.
1 parent 6b1d898 commit 7cfd9a0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

exts/smallseg.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ def __init__(self):
1616
curpath=_curpath
1717
self.d = {}
1818
print("loading dict...", file=sys.stderr)
19-
self.set([x.rstrip() for x in file(os.path.join(curpath,"main.dic")) ])
20-
self.specialwords= set([x.rstrip().decode('utf-8') for x in file(os.path.join(curpath,"suffix.dic"))])
19+
with open(os.path.join(curpath, "main.dic")) as in_file:
20+
self.set([x.rstrip() for x in in_file])
21+
with open(os.path.join(curpath,"suffix.dic")) as in_file:
22+
self.specialwords= set([x.rstrip().decode('utf-8') for x in in_file])
2123
print('dict ok.', file=sys.stderr)
2224
#set dictionary(a list)
2325
def set(self,keywords):

0 commit comments

Comments
 (0)