Why should input(prompt="hello:") fail?

Peter Hansen peter at engcorp.com
Mon Nov 24 13:14:10 EST 2003


djw wrote:
> 
> 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?

Yes, no...  *if* the input() function supported keyword arguments, then
of course it would respond to a keyword argument of the correct name.

Since it doesn't, you can't exactly say that the name "prompt" is the
proper one to use.  For a Python function, you would of course be able
to go and check the source and, if it used "prompt" for the name of its
sole positional argument, then you could use that name as a keyword 
argument as well.  For the builtin, I think the keyword argument support
has to be provided explicitly, as Michael Hudson is, I think, saying.

-Peter




More information about the Python-list mailing list