PDA

View Full Version : python input question



Mr.popo
February 2nd, 2008, 08:48 PM
Why is it better to use int(raw_input("..")) than input("..").

cheers.

LaRoza
February 2nd, 2008, 08:50 PM
raw_input() will return a string. input() takes commands.

If you have a string, nothing bad can happen, and you can safely check it. input() will allow commands to be executed.

http://linuxgazette.net/issue83/evans.html

User input is the hardest thing in programming to do. Users are...fickle.

In Python 3000, raw_input will be renamed "input()" and the current input() function will be no longer used in that way. You will have to use eval(input()) for the same effect.

Mr.popo
February 2nd, 2008, 08:51 PM
raw_input() will return a string. input() takes commands.

If you have a string, nothing bad can happen, and you can safely check it. input() will allow commands to be executed.

ok, thankyou.

LaRoza
February 2nd, 2008, 08:52 PM
ok, thankyou.

I added more, including a link to an article on user input.

Mr.popo
February 2nd, 2008, 08:58 PM
Yeah, I saw. Thanks for the link.