简体   繁体   English

Python - 有没有办法得到谁在打电话(从 IDLE/Shell 调用)

[英]Python - Is there a way to get who is calling (called from IDLE/Shell)

Is there a way to get is the method called from IDLE/python shell?有没有办法获取从 IDLE/python shell 调用的方法?

For example:例如:

def print_in_console():
    if called_from_python_shell:
        print('Called from console')
    ...do other stuff later

The only feasible (easy) way I can see of doing this is by passing an argument / parameter to the function you're calling.我可以看到这样做的唯一可行(简单)方法是将参数/参数传递给您正在调用的函数。

def function (foo, bar, called_from):
    print (called_from)
    *** do stuff with foo and bar ***

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM