3
有没有办法得到是从IDLE/python shell调用的方法?Python - 有没有办法让谁打电话(从IDLE/Shell调用)
例如:
def print_in_console():
if called_from_python_shell:
print('Called from console')
...do other stuff later
有没有办法得到是从IDLE/python shell调用的方法?Python - 有没有办法让谁打电话(从IDLE/Shell调用)
例如:
def print_in_console():
if called_from_python_shell:
print('Called from console')
...do other stuff later
唯一可行的办法,我可以看到这样做的是通过传递一个参数给你打电话,让它知道了它是从调用的函数,此时您无论如何,你都会知道你在哪里叫它。
你可以在'sys.argv'中寻找差异,但这仍然不确定。 – cco