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.
我想检测用户是否正在运行 bpython shell。
我环顾四周,但找不到任何看起来有用的东西。例如,尝试导入 bpython 并依赖它是误报,因为用户可能安装了 bpython 但实际上运行的是完全不同的 shell。
有这样做的好方法吗?
以下适用于我的系统,但我不确定它的便携性:
import sys from pathlib import Path executable_name = Path(sys.argv[0]).name is_bpython = executable_name == 'bpython'
请注意,通过将非 bpython 解释器重命名为bpython或重命名bpython为其他名称,可能很容易欺骗此方法。
bpython