Let's consider the following file myfile.py
.
def f_1():
print("Run !")
def f_2():
print("Run, run !")
class Test():
def __new__(cls):
print("In the class", dir())
print("After class", dir())
Test()
I would like to access to all the functions defined before my class within it. The inside dir is about the class and not the file as the output above shows.
After class ['Test', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'f_1', 'f_2']
In the class ['cls']
One solution would be to add a global constant previousnames = dir()
just before the class but is there a better way to do that ?