0
def my_function():
   ... 

my_variable = my_function
my_variable()

In this case, is there a way to get my_variable as string from inside my_function?

Some Guy
  • 576
  • 1
  • 4
  • 17

1 Answers1

1

You could look into globals() for instances of the function.

def my_func():
    names = [k for k,v in globals().items() if str(v).startswith("<function my_func ")]
    print(names[1:]) #names[0] is "my_func"

my_var = my_func
my_var() #['my_var']

asd = my_func
asd() #['my_var', 'asd']
alec_djinn
  • 10,104
  • 8
  • 46
  • 71