I want to create a library similair to logging in python. Example from python api below:
import logging
import mylib
def main():
logging.basicConfig(filename='myapp.log', level=logging.INFO)
logging.info('Started')
mylib.do_something()
logging.info('Finished')
if __name__ == '__main__':
main()
import logging
def do_something():
logging.info('Doing something')
INFO:root:Started
INFO:root:Doing something
INFO:root:Finished
Notice how logging was able to get its config set in one module and have the other module use it without the second module repeating. Currently, I can make something similar with global variables in the library... but that just feels sloppy.
str = ''
def setStr(input):
global str
str = input
def getStr():
retu str
Now I can import in modules and update them...
import library
import module2
library.setStr('wow')
module2.run()
import library
def run():
print(library.getStr())
wow
For my project I will have to use a lot of global variables and it will look sloppy. So how do I do this? Thanks in advance.
