Python Python Basics Meet Python Syntax and Errors

I didn't understand why it says 'line 2' when the error was on 1


5 Answers

Mitchell is close. Yes the error is on line 1 because of the missing parentheses. But what is happening is the python is looking for line 2 for the closing parentheses and since it doesn't find it there or any continuing code it gives the EOF error. Something that you will learn further on is that not all python code needs to be on the same line, a line of code can actually span several lines of code. It is a capability to allow developers to make their code more readable, but I will let Craig get to that later.

What Bryan said is correct, it keeps on looking for that parentheses even on the next line

Mitchell Clark
Mitchell Clark
238 Points

I am new. But my understanding is that the interpreter looked for the closing parentheses for the string in the rest of the script, but it failed and spat out EOF (End Of File) Line 2 because Line 2 is where the file ended, not Line 1.

its right answr

Tom Vinkovich
Tom Vinkovich
Pro Student 514 Points

If the example shows this... Treehouse:~/workspace$ python Traceback (most recent call last): File "", line 1, in <model> Print ("Hello, World") NameError: name 'Print@ is not defined treehouse:~/workspace$ python File "", line 2

Within the console...line 1 shows you where the error has occurred within the script and line 2 within the console shows where it is related within the console.

In other words, when it says line 1 it is referring to the script and line 2 is referring to the line within the console.

This is what I think how we should read this...I could be wrong and would love the confirmation because I too was thinking the same thing...

Also new, and learning. Here's my interpretation of the error because this was confusing at first, and hey - more than one perspective helps.

The EOF error message shows because the program run and reaches the end of the file without executing code. After watching the video, we know the missing parentheses is the culprit. The "Line 2" is shown in the error message because there is logic on line 1 that did not produce output before getting to the end of the file. With a little deductive reasoning, we're able to infer that line 1 is where the error occurs.

I tried out the following code: print("Where's EOF now?")

this is a test to see where the EOF occurs... suspect is that it will be EOF line 4

print("Hello world!"

The output: the SyntaxError EOF error returns on 4.

So, with longer files, deductive reasoning may be more time-consuming. That being said, we know that this reached the end of the file (line 4 in the example above) without any other errors, so this may be a way to indicate it's not a "hard error" and give us something to look for when revising (in this case, a missing parenthesis).