in a function
def fun():pass
How does the function
know who called it?In a C language, it seems difficult. But in python it’s very simple
import traceback
def fun():
s = traceback.extract_stack()
print '%s Invoked me!'%s[-2][2]
the fun function will tell you who called it and print it out, so let’s try it:
>>> def a():fun()
>>> def b():fun()
>>> a()
a Invoked me!
>>> b()
b Invoked me!
>>>
div>
Read More:
- Solution of Greenplum query calling function error
- Error: Exception was raised when calling per-thread-terminate function in extension lrwreplaymain.dl
- C++: terminate called after throwing an instance of ‘std::length_error‘ (sort function cmp sorting rules problem)
- To solve the problem of flashback of calling class function of glutsolidcube() in Win32 program
- Explanation of the function strip(), lstrip(), rstrip() in Python
- Deep learning: derivation of sigmoid function and loss function
- Golang timer function executes a function every few minutes
- PHP function file_ get_ Contents() reports an error when using HTTPS protocol: SSL operation failed
- Ioremap function and iounmap() function
- How to use Python split() function (split array)
- Python error prompt: typeerror: ‘builtin’_ function_ or_ method‘ object is not subscriptable
- error C4996: ‘scanf‘: This function or variable may be unsafe.Visual Studio Series compilers report errors using scanf function
- Python – [encoding] in Python os.system Solution to Chinese garbled code when calling CMD command
- Python TypeError: ‘newline’ is an invalid keyword argument for this function
- Java get try, catch error information data
- C / C + + rounding function: round function
- About the problem of calling tools library by running Python program under Mac OS X, modulenotfoundererror: no module named ‘tools‘
- Tensorflow in function tf.Print Method of outputting intermediate value
- Error occurred when Python called cv2.findcontours: valueerror: not enough values to unpack (expected 3, got 2)
- CIN in C + + cin.get ()、 cin.getline (), getline(), gets() function