python 3.12 中 init 中的属性不可用
在 python 3.12 中编写了一个程序,但是运行时遇到了一个错误,提示“attributeerror:getconfig 对象没有属性 conf”。
错误代码如下:
class getconfig(object): def __int__(self): # 创建一个属性 self.conf = configparser.configparser() def get_db_host(self): return self.conf.get("db", "host") if __name__ == "__main__": gc1 = getconfig() var = gc1.get_db_host()