如何查看python是在控制台还是在shell

时间:2017-03-20 18:38:23

标签: python python-2.7 python-3.x python-idle

所以我目前正在编写一个使用

的python程序
getpass.getpass()

函数,但是这不能在IDLE shell中工作,只是控制台/终端,所以无论如何都要查看我是在python shell还是在console / terminal中运行程序。所以,如果是这样,我可以做类似的事情:

if python == 'console':
    a = getpass.getpass()

elif python == 'idle':
    a = input()

如果可以,这将是非常有用的,所以希望你可以。

1 个答案:

答案 0 :(得分:1)

从IDLE运行时

import sys; 'idlelib' in sys.modules是正确的,而不是从终端运行时(除非你的程序导入它)。