Aug-21-2022, 06:56 PM
(Aug-14-2022, 12:59 AM)bowlofred Wrote: You could try inspect.stack()[1][4][0]
and see if that is useful.
i tried it like this:Output:lt1a/forums/1 /home/forums 12> cat func_name.py
def foo(*args,**kwargs):
import inspect
me = inspect.stack()[1][4][0]
print('i was called as',repr(me),flush=True)
return me
bar = foo
print(f'woot {foo()},{bar(456)}',flush=True)
lt1a/forums/1 /home/forums 13> python3.8 func_name.py
i was called as "print(f'woot {foo()},{bar(456)}',flush=True)\n"
i was called as "print(f'woot {foo()},{bar(456)}',flush=True)\n"
woot print(f'woot {foo()},{bar(456)}',flush=True)
,print(f'woot {foo()},{bar(456)}',flush=True)
lt1a/forums/1 /home/forums 14>
but that was not what i wanted. i only want the name. with this i would need to parse the line (not too hard) and determine which name this call was (much harder).
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.