close

[Solved] Token error: EOF in multi-line statement

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Token error: EOF in multi-line statement in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Token error: EOF in multi-line statement Error Occurs?

Today I get the following error Token error: EOF in multi-line statement in python.

How To Solve Token error: EOF in multi-line statement Error ?

  1. How To Solve Token error: EOF in multi-line statement Error ?

    To Solve Token error: EOF in multi-line statement Error Your first line in choices variable doesn't have an apostrophe (') at the end.

  2. Token error: EOF in multi-line statement

    To Solve Token error: EOF in multi-line statement Error Your first line in choices variable doesn't have an apostrophe (') at the end.

Solution 1

Not a direct answer to the original question, but since online searching brought me here… I got this error for another reason: a stray parenthesis! But it came from flake8. Here’s a snippet of code to reproduce it:

import socket


def all_good(name):
    name_line = f"Name: {name}")
    print(name_line)

I saved this into a file called error.py. Now if I run flake8 on it:

$ flake8 error.py 
error.py:1:1: E902 TokenError: EOF in multi-line statement

Which is rather puzzling as there is no multi-line statement anywhere! Eventually I found the bug, but the moral of the story is that I’d have found it much quicker if I had run it through the python interpreter:

$ python3 error.py 
  File "error.py", line 5
    name_line = f"Name: {name}")
                               ^
SyntaxError: unmatched ')'

Fix it:

import socket


def all_good(name):
    name_line = f"Name: {name}"
    print(name_line)

And now flake8 will actually do it’s job:

$ flake8 error.py 
error.py:1:1: F401 'socket' imported but unused

It’s obvious, but remember: check the code with python3 first, then run it through linters or other checkers.

Solution 2

Your first line in choices variable doesn’t have an apostrophe (') at the end.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read