'Python import single global variable without initializing others

I think my doubt can be best explained with an example.

# module1
def create_logger():
    return <some_logger_object>

def access_dir(dir):
    # do something with the dir

a = create_dir()
b = access_the_dir(#some env var)

# module2
from module1 import a

a.info("something")

Now when I am trying to import only 'a' from module1, still 'b' is being called and it is giving me an error because the code can't find the env var at that time.

But I need to have the global variable 'b' as it is being used somewhere else in the code. But in one part of the logic, I don't need 'b' and can't really initialize it because the env var comes from a job that hasn't been run yet.

Another problem is that create_logger() and access_dir() are both basically part of the same business logic. Hence moving them to a different module doesn't really makes any sense.

So, is there any other way it can be achieved? I need to import one global variable from a module without initializing others.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source