import inspect
def call_1():
sample = inspect.stack(1)[1]
file_name = sample[1]
line_num = sample[2]
method_name = sample[3]
format_mes = "File:%s Line:%s Method:%s"
res = format_mes % (file_name, line_num, method_name)
print res
def call_2():
call_1()
def call_3():
call_2()
# Example
print "--------------------"
call_2()
print "--------------------"
call_3()
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme