Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 追加类中声明的列表变量_Python 3.x - Fatal编程技术网

Python 3.x 追加类中声明的列表变量

Python 3.x 追加类中声明的列表变量,python-3.x,Python 3.x,我正在尝试附加数据列表,如下所示 class Message: def __init_(self): self.header = 0 self.process= 0 self.status= 0 self.datasize= 0 self.data= [] self.lrc= 0 def append(self, byte): return self.data.app

我正在尝试附加数据列表,如下所示

class Message:
    def __init_(self):
        self.header = 0
        self.process= 0
        self.status= 0
        self.datasize= 0
        self.data= []
        self.lrc= 0

    def append(self, byte):
        return self.data.append(byte)

if __name__ == '__main__':
    flagsbyte = 5
    CurrentTxMsg = Message()
    CurrentTxMsg.append(flagsbyte)
但是,我不断收到错误消息
没有属性数据
。我不明白为什么

   class Message:
        def __init__(self):
            self.header = 0
            self.process= 0
            self.status= 0
            self.datasize= 0
            self.data= []
            self.lrc= 0

        def append(self, byte):
            return self.data.append(byte)

    if __name__ == '__main__':
        flagsbyte = 5
        CurrentTxMsg = Message()
        CurrentTxMsg.append(flagsbyte)

只需将\uuuu init\uuuu替换为打字错误:您的init每边需要两个下划线。因此,您的初始值设定项没有运行。您缺少了一个
\uu
-该方法需要命名为
\uuu init\u
。噢,哇。谢谢