[Tutor] Runs in IDLE with F5, but not in Windows Command Prompt
Danny Yoo
dyoo at hashcollision.org
Thu Apr 25 06:51:24 CEST 2013
On Wed, Apr 24, 2013 at 10:11 PM, boB Stepp <robertvstepp at gmail.com> wrote:
> In my on again, off again studies of Python I am stumped on something
> that ought to be trivial, but I am not seeing it. When I run this
> program (only the part up to where the error occurs is shown):
>
> import random
>
> numberToGuess = random.randint(1, 20)
> numberOfGuesses = 0
>
> print("Hello! What is your name?")
> playerName = input()
Hi Bob,
[The following note is Python 2.0 specific. In Python 3, input() is
semantically different, and safe.]
If you are using Python 2.0, don't use the input() function here to
read strings. It is not safe: backing it is an implicit eval(), and
eval() is dangerous, especially for beginners who won't have the
background to understand the security implications.
Example: if you enter in the following strange-looking input:
(lambda x: x(x))(lambda x:x(x))
then this will crash your program due to a stack overflow. And this
is relatively safe compared to the other craziness you can enter into
input(). This is exactly why tutorials (and most Python programs in
general) should _not_ use input(): it's dangerous in the wrong hands.
Rather, use raw_input() instead.
In Python 3.0, unfortunately, there's going to be a lot of confusion
because input() in Python 3.0 has the behavior of Python 2.0's
raw_input().
More information about the Tutor
mailing list