error with string (beginner)
Jon Clements
joncle at googlemail.com
Sun Jun 25 10:29:38 EDT 2006
Alex Pavluck wrote:
> Hello. I get the following error with the following code. Is there
> something wrong with my Python installation?
>
> code:
> import types
> something = input("Enter something and I will tell you the type: ")
>
> if type(something) is types.IntType:
> print "you entered an integer"
> elif type(something) is types.StringType:
> print "you entered a string"
>
> error:
> String: Source for exec/eval is unavailable
>From the docs:
"""
input( [prompt])
Equivalent to eval(raw_input(prompt)). Warning: This function is not
safe from user errors! It expects a valid Python expression as input;
if the input is not syntactically valid, a SyntaxError will be raised.
Other exceptions may be raised if there is an error during evaluation.
(On the other hand, sometimes this is exactly what you need when
writing a quick script for expert use.)
If the readline module was loaded, then input() will use it to provide
elaborate line editing and history features.
Consider using the raw_input() function for general input from users.
""""
So you want be using raw_input() for starters...
Cheers,
Jon.
More information about the Python-list
mailing list