Python gets the self of the full program

I am programming a program with addon support. Addons are simple python scripts to import them.

import addon1
import addon2
import addon3
myvar = "hello"
def myfunc():
    return "Python is great"
class myclass:
    def __init__(self):
        self.message = "Stackoverflow is great"

Now I want to access all the variables from my program in add-ons (for example, addon1)

So, I want to call an addon with my program as a parameter (like self in classes)

addon1.i_call_you(__program_self__)

So I'm looking for something similar to self in classes for complete python programs.

PS: For understanding:

addon1.py    

def i_call_you(prog):
    print(prog.myvar)
    prog.myfunc()
+4
source share
1 answer

Built-in function

globals()

returns a dictionary with each global variable. This is what you are looking for.

+2
source

Source: https://habr.com/ru/post/1612623/


All Articles