haspirater

detect aspirated 'h' in French words
git clone https://a3nm.net/git/haspirater/
Log | Files | Refs | README

commit c7348f9cf46aba86d35aa2a39d42a52b8a9d9610
parent a47b46bc87755a69669c792c48d562f3c2273ff6
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Tue, 13 Mar 2012 14:16:53 +0100

adapt to use argv

Diffstat:
haspirater.py | 33++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/haspirater.py b/haspirater.py @@ -23,18 +23,25 @@ def lookup(key): raise ValueError return do_lookup(trie, key[1:] + ' ') == '1' +def wrap_lookup(line): + line = line.lower().lstrip().rstrip() + try: + result = lookup(line) + if result: + print("%s: aspirated" % line) + else: + print("%s: not aspirated" % line) + except ValueError: + print("%s: no leading 'h'" % line) + if __name__ == '__main__': - while True: - line = sys.stdin.readline() - if not line: - break - line = line.lower().lstrip().rstrip() - try: - result = lookup(line) - if result: - print("%s: aspirated" % line) - else: - print("%s: not aspirated" % line) - except ValueError: - print("%s: no leading 'h'" % line) + if len(sys.argv) > 1: + for arg in sys.argv[1:]: + wrap_lookup(arg) + else: + while True: + line = sys.stdin.readline() + if not line: + break + wrap_lookup(line)