Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
def a(): """ Need to write something here.""" def test1(): return a() def test2(x): return x
我想在 python 解释器中这样做:
test1() test2(a())
所以我需要做的是我写一个()来让这两个函数(test1(),test2(x))返回不同的结果。
例如,我希望 test1 返回数字 1,而 test2 返回除数字 1 之外的其他内容。
import inspect def a(): s = inspect.stack() if s[1][3] == '<module>': return "From test2" else: return "Not from test2"