令牌错误:多行语句中的 EOF

发布于 2024-12-11 17:51:17 字数 6390 浏览 0 评论 0原文

以下代码给出了此错误“令牌错误:多行语句中的 EOF”。这是什么错误?我该如何修复它?

import easygui
import time
namegui = easygui.enterbox(msg='Enter your name:', title='Name query', default='Gian')
situationgui = easygui.enterbox(msg='Please enter your situation:', title='Thought Log(Situation)')
thoughtsgui = easygui.enterbox(msg='Please enter your thoughts:', title='Thought Log(Thoughts')
emotionsgui = easygui.enterbox(msg='Please enter your emotions: \n Sad, Mad, Hurt, Depressed, Anxious, Tense, etc.', title='Thought Log(Emotions')
behaviorgui = easygui.enterbox(msg='Please enter your behavior:', title='Thought Log(Behavior')


thinking_trapsgui = easygui.enterbox(msg='Please identify your thinking traps: \n \n'
    'FORTUNE-TELLING: This occurs when we predict that things will turn out badly. However, we cannot predict the future because we do not have a magic ball! \n \n'
    'MIND-READING: This happens when we believe that we know what others are thinking and we assume that they are thinking the worst of us. However, we cannot mind-read so we do not know what others are thinking! \n \n'
    'LABELING: Sometimes we talk to ourselves in a mean way and we use a single negative word to describe ourselves. However, this kind of thinking is unfair and we are too complex to be summed up in a single word! \n \n'
    'FILTERING: This happens when we take note of all the bad things that happen, but ignore any good things. \n \n'
    'OVERESTIMATING: This happens when we believe that something that is unlikely to occur is actually about to happen. \n \n'
    'CATASTROPHIZING: This is when we imagine the worst possible thing is about to happen and we will be unable to cope with it. \n \n'
    'OVERGENERALIZING: This is when we use words like always or never to describe situations or events. This is a problematic way of thinking because it does not take all situation or events into account \n \n',
    title='Thought Log(Identify Your Thinking Traps)')

BAI_var = easygui.choicebox(
    msg='Please identify your thinking traps: \n \n',
    title='Thought Log(Identify Your Thinking Traps)',
    choices=('FORTUNE-TELLING: This occurs when we predict that things will turn out badly. However, we cannot predict the future because we do not have a magic ball! \n \n
             'MIND-READING: This happens when we believe that we know what others are thinking and we assume that they are thinking the worst of us. However, we cannot mind-read so we do not know what others are thinking! \n \n'
             'LABELING: Sometimes we talk to ourselves in a mean way and we use a single negative word to describe ourselves. However, this kind of thinking is unfair and we are too complex to be summed up in a single word! \n \n'
             'FILTERING: This happens when we take note of all the bad things that happen, but ignore any good things. \n \n'
             'OVERESTIMATING: This happens when we believe that something that is unlikely to occur is actually about to happen. \n \n'
             'CATASTROPHIZING: This is when we imagine the worst possible thing is about to happen and we will be unable to cope with it. \n \n'
             'OVERGENERALIZING: This is when we use words like always or never to describe situations or events. This is a problematic way of thinking because it does not take all situation or events into account \n \n')


alt_behaviorgui = easygui.enterbox(msg='Please enter alternative behavior:', title='Thought Log(Alt Behavior)')
alt_thoughtsgui = easygui.enterbox(msg='Please enter alternative thoughts:', title='Thought Log(Alt Thoughts)')
yeargui = easygui.enterbox(msg='Enter the current year:', title='Current Year', default='2011')
monthgui = easygui.enterbox(msg='Enter the current month:', title='Current Month')
daygui = easygui.enterbox(msg='Enter the current day:', title='Current Day')
time_hourgui = easygui.enterbox(msg='Enter the current hour:', title='Current Hour')
time_minutegui = easygui.enterbox(msg='Please enter current minutes:', title='Current Minute')
am_pmgui = easygui.enterbox(msg='Please enter either am or pm:', title='AM OR PM')
file = open('Thought Record 1.0.txt', 'a')
file.write(namegui + '\n')
file.write(daygui)
file.write('/')
file.write(monthgui)
file.write('/')
file.write(yeargui)
file.write('\n')
file.write('Your situation:')
file.write(situationgui)
file.write('\n')
file.write('Your thoughts:')
file.write(thoughtsgui)
file.write('\n')
file.write('Your emotions:')
file.write(emotionsgui)
file.write('\n')
file.write('Your behavior:')
file.write(behaviorgui)
file.write('\n')
file.write('Thinking traps:')
file.write(thinking_trapsgui)
file.write('\n')
file.write('Alternative bahvior:')
file.write(alt_behaviorgui)
file.write('\n')
file.write('Alternative thoughts:')
file.write(alt_thoughtsgui)
file.write('\n')
file.write('\n')
file.close()

此错误仅在我添加以下代码行后才出现。

BAI_var = easygui.choicebox(
    msg='Please identify your thinking traps: \n \n',
    title='Thought Log(Identify Your Thinking Traps)',
    choices=('FORTUNE-TELLING: This occurs when we predict that things will turn out badly. However, we cannot predict the future because we do not have a magic ball! \n \n
             'MIND-READING: This happens when we believe that we know what others are thinking and we assume that they are thinking the worst of us. However, we cannot mind-read so we do not know what others are thinking! \n \n'
             'LABELING: Sometimes we talk to ourselves in a mean way and we use a single negative word to describe ourselves. However, this kind of thinking is unfair and we are too complex to be summed up in a single word! \n \n'
             'FILTERING: This happens when we take note of all the bad things that happen, but ignore any good things. \n \n'
             'OVERESTIMATING: This happens when we believe that something that is unlikely to occur is actually about to happen. \n \n'
             'CATASTROPHIZING: This is when we imagine the worst possible thing is about to happen and we will be unable to cope with it. \n \n'
             'OVERGENERALIZING: This is when we use words like always or never to describe situations or events. This is a problematic way of thinking because it does not take all situation or events into account \n \n')

我在 Mac OS X 10.6 上运行 Python 2.5

The following code gives me this error "Token Error: EOF in multi-line statement". What is this error? How can I fix it?

import easygui
import time
namegui = easygui.enterbox(msg='Enter your name:', title='Name query', default='Gian')
situationgui = easygui.enterbox(msg='Please enter your situation:', title='Thought Log(Situation)')
thoughtsgui = easygui.enterbox(msg='Please enter your thoughts:', title='Thought Log(Thoughts')
emotionsgui = easygui.enterbox(msg='Please enter your emotions: \n Sad, Mad, Hurt, Depressed, Anxious, Tense, etc.', title='Thought Log(Emotions')
behaviorgui = easygui.enterbox(msg='Please enter your behavior:', title='Thought Log(Behavior')


thinking_trapsgui = easygui.enterbox(msg='Please identify your thinking traps: \n \n'
    'FORTUNE-TELLING: This occurs when we predict that things will turn out badly. However, we cannot predict the future because we do not have a magic ball! \n \n'
    'MIND-READING: This happens when we believe that we know what others are thinking and we assume that they are thinking the worst of us. However, we cannot mind-read so we do not know what others are thinking! \n \n'
    'LABELING: Sometimes we talk to ourselves in a mean way and we use a single negative word to describe ourselves. However, this kind of thinking is unfair and we are too complex to be summed up in a single word! \n \n'
    'FILTERING: This happens when we take note of all the bad things that happen, but ignore any good things. \n \n'
    'OVERESTIMATING: This happens when we believe that something that is unlikely to occur is actually about to happen. \n \n'
    'CATASTROPHIZING: This is when we imagine the worst possible thing is about to happen and we will be unable to cope with it. \n \n'
    'OVERGENERALIZING: This is when we use words like always or never to describe situations or events. This is a problematic way of thinking because it does not take all situation or events into account \n \n',
    title='Thought Log(Identify Your Thinking Traps)')

BAI_var = easygui.choicebox(
    msg='Please identify your thinking traps: \n \n',
    title='Thought Log(Identify Your Thinking Traps)',
    choices=('FORTUNE-TELLING: This occurs when we predict that things will turn out badly. However, we cannot predict the future because we do not have a magic ball! \n \n
             'MIND-READING: This happens when we believe that we know what others are thinking and we assume that they are thinking the worst of us. However, we cannot mind-read so we do not know what others are thinking! \n \n'
             'LABELING: Sometimes we talk to ourselves in a mean way and we use a single negative word to describe ourselves. However, this kind of thinking is unfair and we are too complex to be summed up in a single word! \n \n'
             'FILTERING: This happens when we take note of all the bad things that happen, but ignore any good things. \n \n'
             'OVERESTIMATING: This happens when we believe that something that is unlikely to occur is actually about to happen. \n \n'
             'CATASTROPHIZING: This is when we imagine the worst possible thing is about to happen and we will be unable to cope with it. \n \n'
             'OVERGENERALIZING: This is when we use words like always or never to describe situations or events. This is a problematic way of thinking because it does not take all situation or events into account \n \n')


alt_behaviorgui = easygui.enterbox(msg='Please enter alternative behavior:', title='Thought Log(Alt Behavior)')
alt_thoughtsgui = easygui.enterbox(msg='Please enter alternative thoughts:', title='Thought Log(Alt Thoughts)')
yeargui = easygui.enterbox(msg='Enter the current year:', title='Current Year', default='2011')
monthgui = easygui.enterbox(msg='Enter the current month:', title='Current Month')
daygui = easygui.enterbox(msg='Enter the current day:', title='Current Day')
time_hourgui = easygui.enterbox(msg='Enter the current hour:', title='Current Hour')
time_minutegui = easygui.enterbox(msg='Please enter current minutes:', title='Current Minute')
am_pmgui = easygui.enterbox(msg='Please enter either am or pm:', title='AM OR PM')
file = open('Thought Record 1.0.txt', 'a')
file.write(namegui + '\n')
file.write(daygui)
file.write('/')
file.write(monthgui)
file.write('/')
file.write(yeargui)
file.write('\n')
file.write('Your situation:')
file.write(situationgui)
file.write('\n')
file.write('Your thoughts:')
file.write(thoughtsgui)
file.write('\n')
file.write('Your emotions:')
file.write(emotionsgui)
file.write('\n')
file.write('Your behavior:')
file.write(behaviorgui)
file.write('\n')
file.write('Thinking traps:')
file.write(thinking_trapsgui)
file.write('\n')
file.write('Alternative bahvior:')
file.write(alt_behaviorgui)
file.write('\n')
file.write('Alternative thoughts:')
file.write(alt_thoughtsgui)
file.write('\n')
file.write('\n')
file.close()

This error only showed up after I added the following lines of code.

BAI_var = easygui.choicebox(
    msg='Please identify your thinking traps: \n \n',
    title='Thought Log(Identify Your Thinking Traps)',
    choices=('FORTUNE-TELLING: This occurs when we predict that things will turn out badly. However, we cannot predict the future because we do not have a magic ball! \n \n
             'MIND-READING: This happens when we believe that we know what others are thinking and we assume that they are thinking the worst of us. However, we cannot mind-read so we do not know what others are thinking! \n \n'
             'LABELING: Sometimes we talk to ourselves in a mean way and we use a single negative word to describe ourselves. However, this kind of thinking is unfair and we are too complex to be summed up in a single word! \n \n'
             'FILTERING: This happens when we take note of all the bad things that happen, but ignore any good things. \n \n'
             'OVERESTIMATING: This happens when we believe that something that is unlikely to occur is actually about to happen. \n \n'
             'CATASTROPHIZING: This is when we imagine the worst possible thing is about to happen and we will be unable to cope with it. \n \n'
             'OVERGENERALIZING: This is when we use words like always or never to describe situations or events. This is a problematic way of thinking because it does not take all situation or events into account \n \n')

I am running Python 2.5 on Mac OS X 10.6

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

请爱~陌生人 2024-12-18 17:51:17

choice 变量中的第一行末尾没有撇号 (')。

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

不是对原始问题的直接答案,但由于在线搜索将我带到这里......我收到此错误的另一个原因是:杂散的括号!但它来自flake8。下面是重现它的代码片段:

import socket


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

我将其保存到名为 error.py 的文件中。现在,如果我在上面运行flake8

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

这相当令人费解,因为任何地方都没有多行语句!最终我发现了这个错误,但故事的寓意是,如果我通过 python 解释器运行它,我会更快地找到它:

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

修复它:

import socket


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

现在 flake8 将真正完成它的工作:

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

这是显而易见的,但请记住:首先使用 python3 检查代码,然后通过 linter 或其他检查器运行它。

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.

番薯 2024-12-18 17:51:17

你错过了算命行的结束语。

这很容易找到,因为这是语法突出显示变得不同的地方。

You're missing the closing quote on the Fortune-Telling line.

That is easy to find because that is where the syntax highlighting becomes different.

治碍 2024-12-18 17:51:17

解决方案:
删除代码的一部分,看看是否会导致该错误消失。
如果是这样,那么问题就出在该部分
如果没有,则找到另一个部分来剪切...提示:您最后处理的部分:)

Solution:
Cut out one section of your code and see if that makes that error goes away.
If it does, then the problem is in side that section
If it does not, then find another section to cut out... hint: The section were you working on last :)

流云如水 2024-12-18 17:51:17

在我在末尾添加一个右括号后,错误“令牌错误:多行语句中的 EOF”消失了。

最后一行

更改前:
过度概括:这是指我们使用“总是”或“从不”等词语来描述情况或事件。这是一种有问题的思维方式,因为它没有考虑所有情况或事件 \n \n')

更改后:
过度概括:这是指我们使用“总是”或“从不”等词语来描述情况或事件。这是一种有问题的思维方式,因为它没有考虑所有情况或事件 \n \n'))

注意:请注意最后添加了一个 )。我已经测试过并且有效。

After I have added one more closing parenthesis at end the error "Token error: EOF in multi-line statement" has disappeared.

Last line

Before change:
'OVERGENERALIZING: This is when we use words like always or never to describe situations or events. This is a problematic way of thinking because it does not take all situation or events into account \n \n')

After change:
'OVERGENERALIZING: This is when we use words like always or never to describe situations or events. This is a problematic way of thinking because it does not take all situation or events into account \n \n'))

Note: Observe at end one more ) has added. I have tested and it worked.

寻找一个思念的角度 2024-12-18 17:51:17

与@Nagev 一样,在线搜索我的问题将我带到了这里。当尝试在仅包含格式错误的 f 字符串的 Jupyter Notebook 单元上运行 black 时,我遇到了相同的错误 EOF in multi-line statements

print(f"{"#"}")

我花了一段时间找出哪个单元格导致了错误,因为错误没有说明。在 Python 终端中运行有问题的单元格表明它仍然需要额外的输入来完成语句,因此当单元格意外结束时 black 会抛出错误。正确的单元格内容应该是:

print(f"{'#'}")

Same as @Nagev, searching online for my issue brought me here. I got the same error EOF in multi-line statement when trying to run black on a Jupyter Notebook cell that just contains an incorrectly formatted f-string:

print(f"{"#"}")

It took me a while to find which of the cells caused the error, as the error doesn't say. Running the problematic cell in a Python terminal shows that it still expected additional input to complete the statement, hence why an error was thrown by black when the cell unexpectedly ended. The correct cell contents should be:

print(f"{'#'}")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文