I’m actually working on a script where i passed a dict in a class constructor.
At starting all my classes was in the same file than the main script.
my main function call the constructor passing a dict.
when i checkek if a key is in value, all is ok :
if "HOSTALIAS" in myDict:
self.__alias=myDict["HOSTALIAS"]
In order doing well things, i want separate classes from main script in a separate file.
So i imported my class like this :
from modules.incident import Incident
All works except the check if key exists. By doing like this, my if is “by passed” as it do not contains my key, but in my constructor, i looped from the keys and i see the searched key.
For the details , i work for dev a checkmk plugin
Main script sample :
from modules.incident import Incident
dict=utils.context #return a dict
def main:
inc=incident(ctx)
incident.py Class file :
class incident :
def __init__ (self, context) :
if "HOSTALIAS" in context:
#NEVER PASSED HERE
self.__alias = context["HOSTALIAS"]
print(context["HOSTALIAS"]) #Return the value expected
what i don’t understand that if i put all this stuff in the same file without import and do not modify the code, it works.
In separate files, i meet this trouble.
Please, someone has some idea, cause i searched on the web and found nothing oO.
Thks in advance