Nov-18-2018, 07:31 PM
i have a module that defines some functions that aid debugging. it checks an environment variable. if that environment variable is defined, it defines the functions to do their thing, which for most involves printing. if that environment variable is not defined then the functions are defined to do nothing and return so that the script can be run without any debugging output to easily see if the output is correct.
what i would like to have is a way for the code doing the importing to specify which environment variable is to be checked when it does the check to determine what it will define. however, since the debugging module comes from a different file, it does not share either global or local namespaces with the code doing the importing. that means this will not be as simple as setting a global variable and checking it. i also would like to have a way for the script to force the debugging functions to be enabled regardless of any environment variable.
the workaround idea i have it to set another environment variable in the script before it imports the module, and have the module check this other environment variable to get the name to use.
so my questions are: how safe is this? what kinds of issues do you see in this? is there a better alternative?
what i would like to have is a way for the code doing the importing to specify which environment variable is to be checked when it does the check to determine what it will define. however, since the debugging module comes from a different file, it does not share either global or local namespaces with the code doing the importing. that means this will not be as simple as setting a global variable and checking it. i also would like to have a way for the script to force the debugging functions to be enabled regardless of any environment variable.
the workaround idea i have it to set another environment variable in the script before it imports the module, and have the module check this other environment variable to get the name to use.
so my questions are: how safe is this? what kinds of issues do you see in this? is there a better alternative?