本文整理汇总了Python中__builtin__.raw_input方法的典型用法代码示例。如果您正苦于以下问题:Python __builtin__.raw_input方法的具体用法?Python __builtin__.raw_input怎么用?Python __builtin__.raw_input使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类__builtin__
的用法示例。
在下文中一共展示了__builtin__.raw_input方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: patch_input
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import raw_input [as 别名]
def patch_input():
def mock_fun(_m=""):
return "mock"
if sys.version_info[0] == 3:
import builtins
save_input = builtins.input
builtins.input = mock_fun
return save_input
elif sys.version_info[0] == 2:
import __builtin__
save_input = __builtin__.raw_input
__builtin__.raw_input = mock_fun
__builtin__.input = mock_fun
return save_input
示例2: revert_input
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import raw_input [as 别名]
def revert_input(saved_input):
if sys.version_info[0] == 3:
import builtins
builtins.input = saved_input
elif sys.version_info[0] == 2:
import __builtin__
__builtin__.raw_input = saved_input
__builtin__.input = saved_input
示例3: _no_raw_input
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import raw_input [as 别名]
def _no_raw_input(self):
"""Raise StdinNotImplentedError if active frontend doesn't support
stdin."""
raise StdinNotImplementedError("raw_input was called, but this "
"frontend does not support stdin.")
示例4: _raw_input
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import raw_input [as 别名]
def _raw_input(self, prompt, ident, parent):
# Flush output before making the request.
sys.stderr.flush()
sys.stdout.flush()
# flush the stdin socket, to purge stale replies
while True:
try:
self.stdin_socket.recv_multipart(zmq.NOBLOCK)
except zmq.ZMQError as e:
if e.errno == zmq.EAGAIN:
break
else:
raise
# Send the input request.
content = json_clean(dict(prompt=prompt))
self.session.send(self.stdin_socket, u'input_request', content, parent,
ident=ident)
# Await a response.
while True:
try:
ident, reply = self.session.recv(self.stdin_socket, 0)
except Exception:
self.log.warn("Invalid Message:", exc_info=True)
except KeyboardInterrupt:
# re-raise KeyboardInterrupt, to truncate traceback
raise KeyboardInterrupt
else:
break
try:
value = py3compat.unicode_to_str(reply['content']['value'])
except:
self.log.error("Got bad raw_input reply: ")
self.log.error("%s", parent)
value = ''
if value == '\x04':
# EOF
raise EOFError
return value
示例5: raw_input
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import raw_input [as 别名]
def raw_input(prompt=''):
#the original raw_input would only remove a trailing \n, so, at
#this point if we had a \r\n the \r would remain (which is valid for eclipse)
#so, let's remove the remaining \r which python didn't expect.
ret = original_raw_input(prompt)
if ret.endswith('\r'):
return ret[:-1]
return ret
示例6: input
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import raw_input [as 别名]
def input(prompt=''):
#input must also be rebinded for using the new raw_input defined
return eval(raw_input(prompt))
示例7: raw_input
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import raw_input [as 别名]
def raw_input(prompt=None):
if prompt:
sys.stdout.write(prompt)
return builtin_raw_input()
示例8: input
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import raw_input [as 别名]
def input(prompt=''):
return builtin_mod.raw_input(prompt)
示例9: confirm
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import raw_input [as 别名]
def confirm(self, activity):
"""Prompt, if self.prompt"""
yes = True
self.doing = u"importing {}".format(activity)
if self.prompt:
yes = False
inp = input(u" OK to import {}? (y/n):".format(activity))
try:
yes = strtobool(inp)
except ValueError:
pass
if not yes:
print(u" Not importing {}".format(activity))
return yes
示例10: raw_input
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import raw_input [as 别名]
def raw_input(*args):
"""Coconut uses Python 3 "input" instead of Python 2 "raw_input"."""
raise _coconut.NameError('Coconut uses Python 3 "input" instead of Python 2 "raw_input"')
示例11: raw_input
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import raw_input [as 别名]
def raw_input(prompt=""):
"""raw_input([prompt]) -> string
Read a string from standard input. The trailing newline is stripped.
If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.
On Unix, GNU readline is used if enabled. The prompt string, if given,
is printed without a trailing newline before reading."""
sys.stderr.flush()
tty = STDIN.is_a_TTY() and STDOUT.is_a_TTY()
if RETURN_UNICODE:
if tty:
line_bytes = readline(prompt)
line = stdin_decode(line_bytes)
else:
line = stdio_readline(prompt)
else:
if tty:
line = readline(prompt)
else:
line_unicode = stdio_readline(prompt)
line = stdin_encode(line_unicode)
if line:
return line[:-1] # strip strailing "\n"
else:
raise EOFError
示例12: input
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import raw_input [as 别名]
def input(prompt=""):
"""input([prompt]) -> value
Equivalent to eval(raw_input(prompt))."""
string = stdin_decode(raw_input(prompt))
caller_frame = sys._getframe(1)
globals = caller_frame.f_globals
locals = caller_frame.f_locals
return eval(string, globals, locals)
示例13: enable
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import raw_input [as 别名]
def enable(return_unicode=RETURN_UNICODE):
global RETURN_UNICODE
RETURN_UNICODE = return_unicode
builtins.raw_input = raw_input
builtins.input = input
示例14: disable
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import raw_input [as 别名]
def disable():
builtins.raw_input = original_raw_input
builtins.input = original_input
示例15: Input
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import raw_input [as 别名]
def Input(prompt=None):
return eval(eg.SimpleInputDialog.RawInput(prompt))
# replace builtin raw_input() with a small dialog