How do you get a function to output its own name without a traceback module?
For example, when the module foo
has a bar
function, in foo.bar()
you would like to print bar
is your name "bar" or "foo.bar".
What should I do now?
#foo.py
def bar():
print "my name is", __myname__ # How do I print this out?
There is no function in Python that determines its own name. It's been suggested before, but it's been rejected.
So if you want to print out your name,
def bar():
print "my name is bar"
#or
print "my name is foo.bar"
def bar():
print "my name is", bar.__name__
import inspect
def foo():
print inspect.stack()[0][3]
497 No exact matches in call to instance method 'append'
506 Understanding How to Configure Google API Key
520 Unable to install versioned in Google Colab
498 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
523 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.