python调用方法或者变量时出现未定义异常的原因,可能会是没有正确实例化

当引用某个模块时

例如

Testpython

import test

class test(object):
    def __init__():
    
        ……
        self.mimi = test
    
    def  test1():
        ……
        test2 = self.mimi.write()

那么在另一个文件中使用Testpython该文件的时候一定要注意实例化类test

import Testpython


action11 =  Testpython.test()

 

否则会出现__init__有定义但是运行提示AttributeError: 'str' object has no attribute……的情形

 

posted @ 2022-12-08 16:46  No九五二七9527  阅读(340)  评论(0)    收藏  举报