From 5aea327a5b5a4fe74b023d6ecad0689a41ee895f Mon Sep 17 00:00:00 2001 From: ines Date: Mon, 20 Mar 2017 22:48:56 +0100 Subject: [PATCH] Add util function to get raw user input --- spacy/util.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spacy/util.py b/spacy/util.py index f8fc76b05..1f1cdbb6e 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -168,6 +168,17 @@ def parse_package_meta(package_path, package, require=True): return None +def get_raw_input(description, default=False): + """Get user input via raw_input / input and return input value. Takes a + description for the prompt, and an optional default value that's displayed + with the prompt.""" + + additional = ' (default: {d})'.format(d=default) if default else '' + prompt = ' {d}{a}: '.format(d=description, a=additional) + user_input = raw_input(prompt) + return user_input + + def print_table(data, **kwargs): """Print data in table format. Can either take a list of tuples or a dictionary, which will be converted to a list of tuples."""