python
  • user-interface
  • tkinter
  • easygui
  • 2011-10-25 3 views 0 likes 
    0

    다음 코드는이 오류 "토큰 오류 : 여러 줄로 된 문에서 EOF"를 표시합니다. 그래도 오류를 찾을 수 없습니다! 어쩌면 다른 누군가가 그것을 볼 것인가?다른 토큰 오류 : 여러 줄로 된 문에서 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)') 
    
    thinking_trapsgui = 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() 
    

    또한 오류가 항상 file.close() 후 마지막 줄을 강조한다. 왜 그런지 모르겠다 고요?

    나는 당신이 변수 thinking_trapsgui에 대한 폐쇄를) 누락 맥 OS X 10.6

    +0

    불필요한 코드가 너무 많습니다. 그것을 [최소 샘플] (http://sscce.org/)로 줄이십시오. – outis

    +0

    감사합니다 Outis :-) 이것은 매우 통찰력이 있습니다. – gian848396

    +1

    구문 강조 (vim, emacs, visual studio, 여러 다른 편집기) 편집기를 사용하면 이러한 유형의 오류가 발생하기 쉽습니다. 더 나은 편집기로 전환하는 것을 고려하십시오 –

    답변

    1

    에 파이썬 2.5을 실행하고 있습니다. 문제가 있는지 확인하십시오.

    A가 없음) 일반적으로 구문 오류가 발생하므로 잘 모르겠지만 EOF 멀티 라인 토큰 오류가이를 가리킬 수 있습니다. 위의

    당신은

    thinking_trapsgui = 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' 
         ) 
    

    마지막으로 쓴

    편집 ')'chioces 인수입니다. 그래서 위의 줄 끝에 다른 ')'을 추가하십시오.

    +0

    누락 된 코드가 어떻게 보이는지 보여주십시오.) 나는 네가하는 말을 보지 못한다. think_trapsgui의 끝에는 a)가 있습니다. – gian848396

    +0

    'think_trapsgui'에 하나,'choices'에 인자 하나를 넣어야합니다! –

    관련 문제