[Tutor] Issue w/ string input "for", "not", "while", "else" etc.
Steven D'Aprano
steve at pearwood.info
Tue Nov 26 23:33:46 CET 2013
On Tue, Nov 26, 2013 at 05:15:31PM +0100, Rafael Knuth wrote:
> Hej there,
>
> simple issue I couldn't find a solution for:
>
> YourName = input(str("What is your name?"))
> print("Hello", YourName)
>
> When executing the program, in case the user input is "for", "not",
> "True", "while" Python interprets that as a command and changes the
> input's color to the corresponding command.
Python does nothing of the sort. Python doesn't know anything about
colours, and doesn't colour text.
What is colouring the text is the environment you are running your code
in. My guess is that you are using IDLE. I would consider that a bug in
IDLE.
There can be various things involved in running a Python script: the OS,
Python itself, an external REPL like IDLE, the operating system's shell,
a web server like Apache, etc. Unfortunately, until you have a bit of
experience and are able to recognise which component is responsible for
what, it can sometimes be tricky to decide what to blame.
That is why it can be important to explain what environment you are
running under or how you are running Python:
"Using Python 3.3 under Windows using IDLE"
"Using Python 2.7 directly under Linux"
sort of thing. Don't worry, as you get more experienced you'll soon pick
up when those details are irrelevant, but until then, better to mention
it when you ask a question.
When using an external REPL (Read, Eval, Print Loop) like IDLE or
bpython, if you run into a tricky problem that doesn't make sense, you
ought to try bypassing that component by running the code directly in
Python. Do I need to explain how to do this, or do you already know?
By the way, "What is your name?" is already a str. Calling str() on it
again does nothing.
--
Steven
More information about the Tutor
mailing list