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