May-02-2023, 04:09 AM
When I write my below code everything works fine:
class HardwareMaintenance: info_dict = dict() def __init__(self): pass def hardware_handler(ConnectHandler, ip=None, self=None): #info_dict = HardwareMaintenance.info_dict info_dict = HardwareMaintenance.info_dict info_dict[ip] = [] if ConnectHandler.device_type == "cisco_ios":I would like to pass info_dict into the __init__ method of the class, however when i reference it inside the hardware_handler function using this method it return a Nonetype:
class HardwareMaintenance: def __init__(self): self.info_dict = dict() def hardware_handler(ConnectHandler, ip=None, self=None): #info_dict = self.info_dict info_dict = self.info_dict info_dict[ip] = []Is there a way where I can initialize info_dict through the __init__ method and call it in my function? Down the line I may inherit the HardwareMaintenance class, and so I would like to have this option of an auto generate dictionary when i do inheritance.