Search code examples
pythonexceptionstdintraceback

What does stdin mean in Python Errors?


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?


Solution

  • 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')