Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在单行中询问多个用户输入_Python_Python 3.x - Fatal编程技术网

Python 在单行中询问多个用户输入

Python 在单行中询问多个用户输入,python,python-3.x,Python,Python 3.x,我使用的是Python3,我正在寻找一种方法,让程序在一行中询问2个用户输入 我正在寻找的输出示例: enter first input: enter second input: 但是,我知道询问多个用户输入的唯一方法是: first_input = input("enter first input: ") second_input = input("enter second input: ") #output enter first input:

我使用的是Python3,我正在寻找一种方法,让程序在一行中询问2个用户输入

我正在寻找的输出示例:

enter first input:                      enter second input:
但是,我知道询问多个用户输入的唯一方法是:

first_input = input("enter first input: ")
second_input = input("enter second input: ")

#output
enter first input:
enter second input: 
我要找的那个可能吗?如果是,有人能教我怎么做吗

choices = raw_input("Please enter two input and seperate with space")
value1, value2 = choices.split(" ")
现在,如果输入
1 56
或类似的内容,则
value1
将为
1
value2
将为
56

您可以为拆分功能选择另一个分隔符。

这在很大程度上取决于环境

以下是仅限windows的解决方案:

from ctypes import *
from ctypes import wintypes

def get_stderr_handle():
    # stdin handle is -10
    # stdout handle is -11
    # stderr handle is -12
    return windll.kernel32.GetStdHandle(-12)

def get_console_screen_buffer_info():
    csbi_ = CONSOLE_SCREEN_BUFFER_INFO()
    windll.kernel32.GetConsoleScreenBufferInfo(get_stderr_handle(), byref(csbi_))
    return csbi_

class CONSOLE_SCREEN_BUFFER_INFO(Structure):
    """struct in wincon.h."""
    _fields_ = [
    ("dwSize", wintypes._COORD),
    ("dwCursorPosition", wintypes._COORD),
    ("wAttributes", wintypes.WORD),
    ("srWindow", wintypes.SMALL_RECT),
    ("dwMaximumWindowSize", wintypes._COORD),
]

csbi = get_console_screen_buffer_info()
first_input = input("enter first input: ")
cursor_pos = csbi.dwCursorPosition
cursor_pos.X = len("enter first input: ") + len(first_input) + 1
windll.kernel32.SetConsoleCursorPosition(get_stderr_handle(), cursor_pos)
second_input = input("enter second input: ")
下面是一个linux解决方案,它使用退格字符。如果您使用的是较旧的python版本,则有一些
get\u terminal\u size()
的实现

from shutil import get_terminal_size
first_input = input("enter first input: ")
second_input = input("\b"*(get_terminal_size()[0] - len("enter first input: ") - len(first_input) - 1) + "enter second input: ")
这可能会有帮助

import sys
inputarr=sys.stdin.read().split()
print("input 1:",inputarr[0])
print("input 2:",inputarr[1])
您可以使用任何其他分隔符


通知我,如果这不是你要找的

要求用户输入两个以空格分隔的数字,然后按enter键。然后拆分():)这是可能的,但需要;如果你刚开始,有些事情并不容易。你确定你想这样做吗?嗯…我想我会试一试…你能告诉我如何在代码之间进行解释吗???这不完全符合询问者的要求。这是我知道的另一种方式。让他来决定。好吧,这对我的朋友很有帮助,谢谢…但是,我正在寻找一个不同的对我不起作用的…输出是一系列框,当我在它们之间单击时,它们会移动。你使用的终端是什么,你指的是pc?终端是什么。。我使用的是一台以Windows7为操作系统的华硕笔记本电脑……我有一个关于你答案的问题,我要找的是不是真的那么依赖于我终端的环境;或者这是我将遇到的少数几个答案中的一个?请尝试在windows 7上测试的windows only解决方案。我的输出没有改变;我想我缺少一些东西,它的easy sys包含系统特定的参数和函数,stdin是解释器标准输入流的文件对象。sys.stdin.read()将从标准输入读取,直到达到EOF为止,而sts.stdin将一次读取一行。嗯…好的..但是,我没有得到inputarr[]部分抱歉,我搞砸了:P它必须是sys.stdin.read().split()“sys.stdin.read()”读取输入文件,直到达到EOF为止,split()没有任何参数类似于split(“”)ie将删除所有空白并将元素放在列表中