简体   繁体   English

python的新手,我收到一个属性错误

[英]new to python and i am getting an attribute error

class newnode:类新节点:

def _init_(self):
    self.x=1
def nextmethod(self,value):
    self.result=value+self.x
    print(self.result)

def main():定义主():

node1=newnode()
node1.nextmethod(6)

if name ==' main ':如果名称=='':

main()

C:/Users/hp/Desktop/untitled0.py", line 5, in nextmethod self.result=value+self.x C:/Users/hp/Desktop/untitled0.py", line 5, in nextmethod self.result=value+self.x

AttributeError: 'newnode' object has no attribute 'x' AttributeError: 'newnode' 对象没有属性 'x'

Just use this code:只需使用此代码:

class newnode:
    def __init__(self):
        self.x=1
    def nextmethod(self,value):
        self.result=value+self.x
        print(self.result)

def main():
    node1=newnode()
    node1.nextmethod(6)

if __name__=='__main__':
    main()

Remember that init has double underscores.请记住, init有双下划线。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在Python中出现此属性错误? - Why am I getting this attribute error in Python? 模块“gridfs”没有属性“get”我在 python 中收到此错误 - module 'gridfs' has no attribute 'get' I am getting this error in python 为什么会出现属性错误? - Why am I getting an attribute error? 为什么会出现属性错误? - why am i getting the attribute error? 我是 python 的新手,我遇到了一个错误:异常:App.root 中的实例无效 - I am new to python I am getting stuck in a error: Exception: Invalid instance in App.root 当我没有为对象分配任何属性时出现属性错误 - Getting an attribute error when I am not assigning any attribute to the object 我收到属性错误为'int' object has no attribute 'to' - I am getting Attribute error as 'int' object has no attribute 'to' python - django:为什么我收到此错误:AttributeError:'method_descriptor'对象没有属性'今天'? - python - django: why am I getting this error: AttributeError: 'method_descriptor' object has no attribute 'today'? 使用Python客户端通过SOAP访问JIRA时出现错误“导入中没有schemaLocation属性” - i am getting error “no schemaLocation attribute in import” when using Python client accessing JIRA via SOAP 在python模块对流层中,我得到一个错误“ AttributeError:'模块'对象没有属性'EBSBlockDeviceMapping'” - In python module troposphere I am getting an error “AttributeError: 'module' object has no attribute 'EBSBlockDeviceMapping'”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM