Merge branch 'master' of github.com:erikcox/cheat into erikcox-master

* 'master' of github.com:erikcox/cheat:
  Added a condition in prompt_yes_or_no() to use input or raw_input
  First attempt at making utils.py compatible with Python 2 and 3.
This commit is contained in:
Chris Lane 2014-10-19 11:02:32 -04:00
commit 6efae113cf
1 changed files with 11 additions and 2 deletions

View File

@ -1,3 +1,4 @@
from __future__ import print_function
import os import os
import sys import sys
@ -47,10 +48,18 @@ def editor():
def prompt_yes_or_no(question): def prompt_yes_or_no(question):
""" Prompts the user with a 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) print(question)
return raw_input('[y/n] ') == 'y' return get_input('[y/n] ') == 'y'
def warn(message): def warn(message):
""" Prints a message to stderr """ """ Prints a message to stderr """
print >> sys.stderr, (message) print((message), file=sys.stderr)