diff options
author | Jeroen Vermeulen <jtv@precisiontranslationtools.com> | 2015-05-25 09:20:12 +0300 |
---|---|---|
committer | Jeroen Vermeulen <jtv@precisiontranslationtools.com> | 2015-05-25 09:20:12 +0300 |
commit | d3597a69e2aab0a7111aae196fd81e310cc70fea (patch) | |
tree | f01493e1cdaddc31f1f7ad08c399826cb72dd83f | |
parent | e85751929300bef48286680a5648c29830fe7cd6 (diff) |
Normalize paths.
This fixes differences between Unix and Windows paths, and makes references
to the user's home directory more portable.
-rwxr-xr-x | mgizapp/scripts/merge_alignment.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/mgizapp/scripts/merge_alignment.py b/mgizapp/scripts/merge_alignment.py index f38feee..a1b7e90 100755 --- a/mgizapp/scripts/merge_alignment.py +++ b/mgizapp/scripts/merge_alignment.py @@ -12,6 +12,13 @@ import codecs import io import os +def normalize_path(path): + path = path.replace('\\', os.sep).replace('/', os.sep) + path = os.path.expanduser(path) + path = os.path.abspath(path) + return path + + if sys.version_info < (3,0,0): sys.stdin = codecs.getreader('UTF-8')(sys.stdin) sys.stdout = codecs.getwriter('UTF-8')(sys.stdout) @@ -30,7 +37,7 @@ sents = []; done = []; for i in range(1,len(sys.argv)): - fname = sys.argv[i].replace('\\', os.sep).replace('/', os.sep) + fname = normalize_path(sys.argv[i]) files.append(io.open(fname, "r", encoding="UTF-8")); ids.append(0); sents.append(""); |