3

When I get a syntax error for example, I get this block of text:

  File "<stdin>", line 1, in ?
    while True print('Hello world')
        while True print('Hello world')
                       ^
SyntaxError: invalid syntax

I did some research and I found out there are three standard streams.

"The three I/O connections are called standard input (stdin), standard output (stdout) and standard error (stderr)."

So why isn't this standard error?

  • Briefly: the error message isn't telling you where the error message was sent, it's telling you where the error occurred. – TigerhawkT3 May 29 '16 at 20:10

2 Answers2

3

Because the source of the code is stdin, e.g. it was typed in at a console.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
0

Your while needs a colon (:). You're getting an error at stdin because you're typing the script on the command line, and python (the python command you are entering text into) is reading it from it's stdin stream (i.e. the terminal). You typed an error into Python's stdin and it's telling you that.

while True:
    print('Hello world')
mikeb
  • 10,578
  • 7
  • 62
  • 120