为什么输入(prompt =" hello:")会失败? [英] Why should input(prompt="hello:") fail?

查看:92
本文介绍了为什么输入(prompt =" hello:")会失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

真的很困惑,当我使用关键字样式参数时如下:

input(prompt =" hello" ;)



回溯(最近一次调用最后一次):

文件"< pyshell#52> ;",第1行,在-toplevel-

输入(prompt =" hello")

TypeError:input()不带关键字参数


虽然库引用说函数是:输入([提示])

所以它应该可以工作。:(


我正在使用python 2.3 for windows。

有没有人试过这个?

我是python的新手,请帮助我,谢谢。

解决方案

zhi写道:


当我使用关键字样式参数时,真的很困惑:

input(prompt =" hello")



Traceback(最近一次调用最后一次):
文件"< pyshell#52>",第1行,in -ople /
输入(prompt =" hello")
TypeError:input()不带关键字参数

虽然库引用说的函数是:input([prompt])
所以,它应该工作。:(




不,它不应该。参数没有显示名称,所以你

应该只使用位置参数,如输入(''hello'')。


但是请注意,输入()对于认真工作来说是一个糟糕的选择:你需要快速超越想要使用它并学习

为什么raw_input()是更好的选择。


-Peter


wo ****** @ hotmail.com (zhi)写道:

当我使用关键字样式参数时,真的很困惑:



通常内置函数不接受关键字参数。多年来一直有一个支持他们的温和行动,但是很多很多很多地方都没有达到。


干杯,

mwh

-

Usenet就像一群表演大象的人腹泻 -

庞大,难以改变方向,令人敬畏,娱乐,以及
美元b $ ba来源令人难以置信的粪便量最少

期待它。 - spaf(1992)


Peter Hansen写道:

zhi写道:

>>>输入(prompt =" hello")



Traceback(最近一次调用最后一次):
文件"< pyshell#52>",第1行,in - toplevel-
输入(prompt =" hello")
TypeError:input()不带关键字参数

虽然库引用说的函数是:input([prompt] )
所以,它应该可以工作。:(



不,它不应该。参数没有显示名称,所以你
应该是使用一个位置参数,如输入(''你好'')。

请注意,输入()对于认真工作来说是一个糟糕的选择:你应该快速通过想要使用它并学习
为什么raw_input()是一个更好的选择。

-Peter




没有''这更多地与std.lib中基于C和Python

的模块之间的区别有关吗?


关于这个主题的讨论:
http://tinyurl.com/wcgn

我的抽查表明您可以使用
$中显示的关键字args b $ b文档,只要它是基于Python的模块。基于C语言的模块看起来像是b / b
,有些支持它,有些则不支持。我实际上认为这可以对文档进行改进 - 实际上显示了函数定义的方式

,这样就可以清楚地知道什么(如果有的话)关键字args是可能的。


目前这些文档很模糊,例如内置文件:


#函数如文档所示:

cmp(x,y)

cmp(x = 1,y = 2)
TypeError:cmp()不带关键字参数


(我会假设cmp()有C实现吗?)


In日历:


#函数如文档所示:

leapdays(y1,y2)

calendar.leapdays(y2 = 2004) ,y1 = 2003)



0


我同意对于标准的,使用频繁的函数/方法,这可能是

好​​的,但看起来确实不一致。当然对于单个参数

方法,比如OP询问(input()),有一个关键字添加非常值

一点价值。


-Don


Really confused, when I use keyword style argument as following:

input(prompt="hello")



Traceback (most recent call last):
File "<pyshell#52>", line 1, in -toplevel-
input(prompt="hello")
TypeError: input() takes no keyword arguments

While the library reference says the function is: input( [prompt])
so, it should work.:(

I am using python 2.3 for windows.
Have anyone tried this?
I am new to python, please help me, thanks.

解决方案

zhi wrote:


Really confused, when I use keyword style argument as following:

input(prompt="hello")



Traceback (most recent call last):
File "<pyshell#52>", line 1, in -toplevel-
input(prompt="hello")
TypeError: input() takes no keyword arguments

While the library reference says the function is: input( [prompt])
so, it should work.:(



No, it shouldn''t. The argument is not shown with a name, so you
are supposed to use just a position argument, as in input(''hello'').

Note however that input() is a poor choice for serious work: you
should quickly get past the point of wanting to use it and learn
why raw_input() is a better choice.

-Peter


wo******@hotmail.com (zhi) writes:

Really confused, when I use keyword style argument as following:



Often builtin functions don''t take keyword arguments. There''s been a
gentle move towards supporting them over the years, but there are
many, many places that haven''t been reached.

Cheers,
mwh

--
Usenet is like a herd of performing elephants with diarrhea --
massive, difficult to redirect, awe-inspiring, entertaining, and
a source of mind-boggling amounts of excrement when you least
expect it. -- spaf (1992)


Peter Hansen wrote:

zhi wrote:


Really confused, when I use keyword style argument as following:

>>> input(prompt="hello")



Traceback (most recent call last):
File "<pyshell#52>", line 1, in -toplevel-
input(prompt="hello")
TypeError: input() takes no keyword arguments

While the library reference says the function is: input( [prompt])
so, it should work.:(



No, it shouldn''t. The argument is not shown with a name, so you
are supposed to use just a position argument, as in input(''hello'').

Note however that input() is a poor choice for serious work: you
should quickly get past the point of wanting to use it and learn
why raw_input() is a better choice.

-Peter



Doesn''t this have more to do with the difference between C-based and Python
based modules in the std. lib?

Discussion on this topic:
http://tinyurl.com/wcgn

My spot checking indicates that you can use keyword args as shown in the
documentation, as long as its a Python based module. C-based modules seem
to be hit-or-miss, some support it, some don''t. I actually think this could
be an improvement to the docs - actually show the way the function is
defined so that it is clear what (if any) keyword args are possible.

The docs are ambiguous about this currently, for example, in builtins:

# Function as shown in docs:
cmp(x,y)

cmp(x=1,y=2) TypeError: cmp() takes no keyword arguments

(I would assume that cmp() has a C implementation?)

In calendar:

# Function as shown in docs:
leapdays(y1,y2)
calendar.leapdays(y2=2004,y1=2003)


0

I agree that for standard, heavily used functions/methods, this is probably
OK, but it does seem rather inconsistent. Certainly for single parameter
methods like the OP asked about (input()), having a keyword adds very
little value.

-Don


这篇关于为什么输入(prompt =&quot; hello:&quot;)会失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆