如何解决第二个脚本(虚线下方)中的EOF问题?

How can I fix EOF problem in the second script (below the dotted line)?

提问人:sidereal 提问时间:10/26/2020 更新时间:10/26/2020 访问量:56

问:

该程序实质上分别对消息和代码进行编码和解码。到目前为止,我只做了解码部分。但是,即使我确保结束括号,检查我的语法并不断篡改它,我仍然收到EOF错误。不幸的是没有运气。有谁知道为什么这个错误不断弹出?我将不胜感激。我还复制了我正在使用的两个文件。

from LetterCodeLogic import LCL

def main():
    print("Welcome to the LetterCode program")

choice = getChoice()
while choice !=0:
    if choice == 1:
        #Encode logic...
        print()
    elif choice == 2:
        #Decode logic...
        msg = input("Enter your numbers to decode (separate with commas): ")
        #send msg to Decode function in LCL class (LetterCodeLogic.py file)
        result = LCL.Decode(msg)
        print("Your decoded message is: \n" + result)
    else:
        print("Unknown process...")
    print()
    choice = getChoice()
print("Thanks for using the Letter Code program")

def getChoice():
    c = int(input("Choice? (1=Encode, 2=Decode, 0=Quit): "))
    return c

if __name__ == "__main__":
    main()

class LCL:
"""Encode/Decode Functions"""

@staticmethod
def Decode(msg):
    #separate numbers from msg string (e.g., "1,2,3")
    nums = msg.split(",")   #produces list of separate items
    result = ""
    for x in nums:
        try:
            n = int(x.strip())  #remove leading/trailing spaces...
            if n == 0:
                c = " "
            elif n < 0 or n > 26:
                c = "?"
            else:
                #ASCII scheme has A=65, B=66, etc.
                c = chr(n+64)
        except ValueError:
            c = "?"
            
        result += c     #same as: result = result + c
        
    return result


@staticmethod
def Encode(msg):
python-3.x eof

评论

0赞 DYZ 10/26/2020
哪个文件导致了问题?第一个文件中有一个未完成的函数,那个函数绝对是非法的。
0赞 Tadhg McDonald-Jensen 10/26/2020
请详细说明您遇到的错误是什么,EOF是文件结束的缩写,它与读取您没有执行的文件有关。哪一行抛出错误?另外,请正确格式化代码,将代码粘贴到 SO 中,然后突出显示它并单击按钮以正确格式化它,截至目前,它看起来存在缩进不一致。{}
1赞 John Gordon 10/26/2020
我不断收到 EOF 错误告诉我们错误不是很有帮助。向我们展示错误。
0赞 sidereal 10/26/2020
哦,对不起。错误位于文件 2 中(底部)。该错误特别指出“解析时出现意外的 EOF”。它将其扔到第二个文件的最后一行。

答:

0赞 sidereal 10/26/2020 #1

“@staticmethod”和“def Encode()”函数为空,这是行解析错误的结尾。当我对此进行编码并运行它时,它运行没有任何问题。所以我暂时删除了它。