[Tutor] how to accept an integer?
Alan Gauld
alan.gauld at btinternet.com
Thu Dec 6 00:41:57 CET 2007
"Mahesh N" <mahesh.mach at gmail.com> wrote
> PS : I understand that i can do type conversion after getting input
> thru
> 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
This suggests that you have a variable somewhere called input
that is hiding the function. Try doing del(input)
and try it again.
As to what input does; it evaluates whatever string you give
to it so if your user types in some malicious Python code
input will execute it. For that reason input is usually frowned
on as a security risk and int(raw_input()) is preferred.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list