I'm developing a python library which interfaces its functionalities through a class. The user of the library needs to intantiate this when first importing it into their project. After this the library object would have some state which I want to be sharable across the entire project of the user.
Something like this:
Library
class Lib():
def __init__(self, msg):
self.msg = msg
def print_msg():
print(self.msg)
submod1
from lib import Lib
def test():
# something like this
Lib.print_msg()
submod2
from lib import Lib
def test():
# something like this
Lib.print_msg()
User's main
from lib import Lib:
import submod1, submod2
lib = Lib('message')
submod1.test()
submod2.test()
Output
message
message