yesno_prompt(问题
yesno_prompt( issue
我的代码是这样的:
highpri = yesno_prompt(
["1"], "Flag this message/s as high priority? [yes|no]")
if not "YES" in highpri:
prioflag1 = ""
prioflag2 = ""
else:
prioflag1 = ' 1 (Highest)'
prioflag2 = ' High'
但是当我 运行 它时,我得到:
Traceback (most recent call last):
File "mailerproj.py", line 138, in <module>
highpri = yesno_prompt(
NameError: name 'yesno_prompt' is not defined
所以我尝试了:
highpri = input(
但它给出了这个问题:
Traceback (most recent call last):
File "mailerproj.py", line 139, in <module>
["1"], "Flag this message/s as high priority? [yes|no]")
TypeError: [raw_]input expected at most 1 arguments, got 2
所以在这种情况下,是输入最好但结构错误还是yes/no提示正确但结构错误?
此代码显示了对 input()
如何在 Python 中工作的根本误解 3.
首先,Python3中的input()
函数等同于Python2中的raw_input()
,你的错误说明你使用的是Python2 .
那么让我们阅读您收到的错误消息:
我们知道错误在哪一行:
File "mailerproj.py", line 139, in <module>
它向我们展示了这一行:
["1"], "Flag this message/s as high priority? [yes|no]")
然后它解释了问题:
TypeError: [raw_]input expected at most 1 arguments, got 2
这意味着您给了 input()
错误的参数 - 您给了它两个 ["1"]
和 "Flag this message/s as high priority? [yes|no]"
而它期望一个。
这是关于 raw_input
的 python 帮助:
有关模块 builtin 中内置函数 raw_input 的帮助:
raw_input(...)
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.
所以你需要给它一个参数作为输入。这可以是字符串(例如 "Hello"
)、整数(例如 125
)、浮点数(例如 3.14
)、列表、元组、布尔值等。它将returns一个字符串转化为变量。
您需要让您的代码看起来更像这样:
highpri = raw_input("[1] Flag this message as high priority? [yes|no] > ")
highpri = highpri.upper() # Make the input uppercase for the if
if highpri != 'YES': # If it is not yes, remove the flags.
prioflag1 = ''
prioflag2 = ''
else: # If the input is yes, set the flags.
prioflag1 = '1 (Highest)'
prioflag2 = 'High'
我的代码是这样的:
highpri = yesno_prompt(
["1"], "Flag this message/s as high priority? [yes|no]")
if not "YES" in highpri:
prioflag1 = ""
prioflag2 = ""
else:
prioflag1 = ' 1 (Highest)'
prioflag2 = ' High'
但是当我 运行 它时,我得到:
Traceback (most recent call last):
File "mailerproj.py", line 138, in <module>
highpri = yesno_prompt(
NameError: name 'yesno_prompt' is not defined
所以我尝试了:
highpri = input(
但它给出了这个问题:
Traceback (most recent call last):
File "mailerproj.py", line 139, in <module>
["1"], "Flag this message/s as high priority? [yes|no]")
TypeError: [raw_]input expected at most 1 arguments, got 2
所以在这种情况下,是输入最好但结构错误还是yes/no提示正确但结构错误?
此代码显示了对 input()
如何在 Python 中工作的根本误解 3.
首先,Python3中的input()
函数等同于Python2中的raw_input()
,你的错误说明你使用的是Python2 .
那么让我们阅读您收到的错误消息:
我们知道错误在哪一行:
File "mailerproj.py", line 139, in <module>
它向我们展示了这一行:
["1"], "Flag this message/s as high priority? [yes|no]")
然后它解释了问题:
TypeError: [raw_]input expected at most 1 arguments, got 2
这意味着您给了 input()
错误的参数 - 您给了它两个 ["1"]
和 "Flag this message/s as high priority? [yes|no]"
而它期望一个。
这是关于 raw_input
的 python 帮助:
有关模块 builtin 中内置函数 raw_input 的帮助:
raw_input(...)
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.
所以你需要给它一个参数作为输入。这可以是字符串(例如 "Hello"
)、整数(例如 125
)、浮点数(例如 3.14
)、列表、元组、布尔值等。它将returns一个字符串转化为变量。
您需要让您的代码看起来更像这样:
highpri = raw_input("[1] Flag this message as high priority? [yes|no] > ")
highpri = highpri.upper() # Make the input uppercase for the if
if highpri != 'YES': # If it is not yes, remove the flags.
prioflag1 = ''
prioflag2 = ''
else: # If the input is yes, set the flags.
prioflag1 = '1 (Highest)'
prioflag2 = 'High'