Use pathlib instead of os.path

This commit is contained in:
ines 2017-04-15 12:13:00 +02:00
parent 956dc36785
commit 958b12dec8
1 changed files with 4 additions and 3 deletions

View File

@ -139,9 +139,10 @@ def _min_edit_path(cand_words, gold_words):
def read_json_file(loc, docs_filter=None):
if path.isdir(loc):
for filename in os.listdir(loc):
yield from read_json_file(path.join(loc, filename))
loc = Path(loc)
if loc.is_dir():
for filename in loc.iterdir():
yield from read_json_file(loc / filename)
else:
with io.open(loc, 'r', encoding='utf8') as file_:
docs = json.load(file_)