I have a need to add module attributes at run time. For example, when a module is loaded, it reads the file where the data is contained. I would like that data to be available as a module attribute, but the data is only available at run time.
How can I add module attributes at run time?
Thanks @Dharmesh. That was what I needed. There is only one change that needs to be made. The module won’t be importing itself so to get the module object I can do:
setattr(sys.modules[__name__], 'attr1', 'attr1')