【问题标题】:Why is this a python syntax error during an initialisation?为什么这是初始化期间的python语法错误?
【发布时间】:2009-12-23 21:34:05
【问题描述】:

这段代码:

class Todo:
    def addto(self, list_name="", text=""):
        """
        Adds an item to the specified list.
        """
        if list_name == "":
            list_name = sys.argv[2]
            text = ''.join(sys.argv[3:]

        todo_list = TodoList(getListFilename(list_name))

产生语法错误,最后一行的小箭头指向todo_list

TodoList__init__ 方法在这里:

def __init__(self, json_location):
    """
    Sets up the list.
    """
    self.json_location = json_location
    self.load()

我对 Python 有点陌生,所以我看不出我在这里做错了什么。

【问题讨论】:

    标签: python syntax syntax-error


    【解决方案1】:

    你需要关闭它)

    text = ''.join(sys.argv[3:]
    

    【讨论】:

    • 史诗掌纹。自我注意:解释器在定位语法错误方面不是很准确。下次检查更详细。
    • @Macha:实际上,定位语法错误非常准确。不要让您对先前代码行的假设影响您对错误消息的解释。声明 -- 没有结束 ) 可以继续,直到很明显缺少一些标点符号。
    猜你喜欢
    • 1970-01-01
    • 2020-10-17
    • 2014-07-22
    • 2021-01-12
    • 2017-06-19
    • 2015-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多