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

时间:2011-10-25 05:42:42

标签: python tkinter eof easygui

以下代码给出了此错误“令牌错误:多行语句中的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

5 个答案:

答案 0 :(得分:18)

您的第一行选择变量最后没有撇号(')。

答案 1 :(得分:5)

你错过了Fortune-Telling系列的收盘价。

这很容易找到,因为这是语法高亮变得不同的地方。

答案 2 :(得分:2)

解决方案: 剪下代码的一部分,看看是否会导致该错误消失。 如果确实如此,则问题出在那一节 如果没有,那么找另一个要删除的部分......提示:这部分是你最后做的那样:)

答案 3 :(得分:2)

这不是原始问题的直接答案,但是由于在线搜索将我带到了这里...我收到此错误的另一个原因是:圆括号。但这来自 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检查代码,然后通过短毛绒或其他检查器运行它。

答案 4 :(得分:0)

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

最后一行

更改前: '过度概括:这是当我们使用诸如总是或从不这样的词语来描述情况或事件时。这是一种有问题的思考方式,因为它没有将所有情况或事件都考虑在内\ n \ n')

更改后: '过度概括:这是当我们使用诸如总是或从不这样的词语来描述情况或事件时。这是一种有问题的思考方式,因为它没有将所有情况或事件都考虑在内\ n \ n'))

注意:在末尾再观察)已添加。我已经测试过并且有效。