From d1d5d84e4cb0c223bf07c4f7019e68aad0888c33 Mon Sep 17 00:00:00 2001 From: Erik Cox Date: Sat, 13 Sep 2014 15:09:40 -0700 Subject: [PATCH 1/2] First attempt at making utils.py compatible with Python 2 and 3. --- cheat/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cheat/utils.py b/cheat/utils.py index 4010c15..b2ea17f 100644 --- a/cheat/utils.py +++ b/cheat/utils.py @@ -1,3 +1,4 @@ +from __future__ import print_function import os import sys @@ -53,4 +54,4 @@ def prompt_yes_or_no(question): def warn(message): """ Prints a message to stderr """ - print >> sys.stderr, (message) + print((message), file=sys.stderr) From dde3acf109d48d0cc25213e14e1582169c68a160 Mon Sep 17 00:00:00 2001 From: Erik Cox Date: Sat, 13 Sep 2014 15:46:57 -0700 Subject: [PATCH 2/2] Added a condition in prompt_yes_or_no() to use input or raw_input --- cheat/utils.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cheat/utils.py b/cheat/utils.py index b2ea17f..28ba2eb 100644 --- a/cheat/utils.py +++ b/cheat/utils.py @@ -48,8 +48,16 @@ def editor(): def prompt_yes_or_no(question): """ Prompts the user with a yes-or-no question """ + # Support Python 2 and 3 input + # Default to Python 2's input() + get_input = raw_input + + # If this is Python 3, use input() + if sys.version_info[:2] >= (3, 0): + get_input = input + print(question) - return raw_input('[y/n] ') == 'y' + return get_input('[y/n] ') == 'y' def warn(message):