使用了python 3.12编写下列程序 运行时报错
class GetConfig(object):
def __int__(self):
current_dir = os.path.dirname(os.path.abspath(__file__))
print(current_dir)
sys_cfg_file = os.path.join(current_dir, "sysConfig.cfg")
self.conf = configparser.ConfigParser()
self.conf.read(sys_cfg_file)
def get_db_host(self):
db_host = self.conf.get("DB", "host")
return db_host
if __name__ == "__main__":
gc1 = GetConfig()
var = gc1.get_db_host()
报错信息:
Traceback (most recent call last):
File "D:\Code\InterfaceCrawlTool\getConfig.py", line 48, in <module>
var = gc1.get_db_host()
^^^^^^^^^^^^^^^^^
File "D:\Code\InterfaceCrawlTool\getConfig.py", line 21, in get_db_host
db_host = self.conf.get("DB", "host")
^^^^^^^^^
AttributeError: 'GetConfig' object has no attribute 'conf'
为什么会提示找不到属性呢?我尝试在__init__方法中加入self.name="test",然后使用
gc1 = GetConfig()
gc1.name 也是报同样的错误
你写的是__int__,不是__init__