From 17c23c5d2b6680f90117a7804e65dd7fe541848f Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Sun, 18 Aug 2013 16:54:53 -0400 Subject: try to fix the alignment_to_sexp function --- string_utils.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'string_utils.py') diff --git a/string_utils.py b/string_utils.py index c4439da..12d22b8 100644 --- a/string_utils.py +++ b/string_utils.py @@ -172,9 +172,14 @@ def alignment_to_sexp(alignment, sexp, l2): if index == -1: break else: - re.sub("(?P\d+ \d+ \d+ \d+\s) \w+(?P\)+$)", - "\g{0}\g".format( - " ".join([l2[i] for i in list(index)])), - line) - line.encode('string-escape') + if type(index) == tuple: + word = " ".join([l2[i] for i in list(index)]) + else: + try: + word = l2[index] + except IndexError: + print index + word = word.encode("utf-8").encode("string-escape") + re.sub("(?P\d+ \d+ \d+ \d+\s) \w+(?P\)+$)", + "\g{0}\g".format(word), line) print line -- cgit v1.2.3-70-g09d2