From 2b984937be300a13d9453e4cea09d8d937b05ec7 Mon Sep 17 00:00:00 2001 From: Rob Speer Date: Thu, 4 Aug 2016 15:16:20 -0400 Subject: [PATCH] consolidate logic about MeCab path length --- wordfreq/mecab.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/wordfreq/mecab.py b/wordfreq/mecab.py index 78d48a9..c91705b 100644 --- a/wordfreq/mecab.py +++ b/wordfreq/mecab.py @@ -22,8 +22,9 @@ def find_mecab_dictionary(names): '/usr/local/lib/mecab/dic', ] full_paths = [os.path.join(path, name) for path in paths for name in names] - for path in full_paths: - if os.path.exists(path) and len(path) <= MAX_PATH_LENGTH: + checked_paths = [path for path in full_paths if len(path) <= MAX_PATH_LENGTH] + for path in checked_paths: + if os.path.exists(path): return path error_lines = [ @@ -32,7 +33,7 @@ def find_mecab_dictionary(names): "the %r package." % suggested_pkg, "", "We looked in the following locations:" - ] + ["\t%s" % path for path in full_paths if len(path) <= MAX_PATH_LENGTH] + ] + ["\t%s" % path for path in checked_paths] skipped_paths = [path for path in full_paths if len(path) > MAX_PATH_LENGTH] if skipped_paths: