[Tutor] how to accept an integer?
bryan.fodness at gmail.com
Wed Dec 5 22:46:20 CET 2007
On Dec 5, 2007 4:16 PM, Jerry Hill <malaclypse2 at gmail.com> wrote:
> On Dec 5, 2007 4:01 PM, Mahesh N <mahesh.mach at gmail.com> wrote:
> > I dun understand the mistake. My aim is to accept an integer number. The
> > python lookup in IDLE asks for a string object but the interpreter
> > with the following error message. Some one pls explain.
> > Thank You
> > PS : I understand that i can do type conversion after getting input
> > raw_input(). But how does input() function work?
> > >>> prompt="temme a number\n"
> > >>> speed =input(prompt)
> > Traceback (most recent call last):
> > File "<pyshell#56>", line 1, in <module>
> > speed =input(prompt)
> > TypeError: 'str' object is not callable
> You have code that you haven't shown us. My crystal ball tells me
> that somewhere above this point you did input = "Some String", thus
> shadowing the builtin input function. Start a new interpreter and try
> again and you should find that it works as expected.
> As I'm sure you'll hear from others, it really is best to use
> raw_input instead. If you want an integer instead of a string, do
> something like this:
> speed = int(raw_input(prompt))
Is this how ALL known integers should be input?
> That way whatever the user types isn't run as python code, just read
> in as a string and then converted into an integer.
> Tutor maillist - Tutor at python.org
"The game of science can accurately be described as a never-ending insult to
human intelligence." - João Magueijo
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor