0

I want to detect if the user is running bpython shell.

I've looked around but couldn't find anything that looked useful. For instance, trying to import bpython and relying on that is a false-positive, because the user could have bpython installed but actually be running completely different shell.

Is there a nice way of doing this?

adder
  • 3,512
  • 1
  • 16
  • 28

1 Answers1

1

The following works on my system , but I'm not sure how portable it is:

import sys

from pathlib import Path


executable_name = Path(sys.argv[0]).name
is_bpython = executable_name == 'bpython'

Note that this method can probably easily be fooled by renaming a non-bpython interpreter to bpython or by renaming bpython to something else.

das-g
  • 9,718
  • 4
  • 38
  • 80