Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upInject a flag variable into the global namespace to indicate to a script that it’s running inside bpython #795
Comments
|
Hey hey, what's the usecase for this? If there's a good one there's no problem in adding this. Is using PYTHONSTARTUP a workaround for now? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be very advantageous if one could easily discern whether or not the execution environment is bpython.
For example, in IPython, the REPL environment sets a global variable
__IPYTHON__toTrue. This allows for trivial tests like e.g.:Contrastingly, I just tried to programmatically figure out if my script was running in bpython or not, and the experience was… wanting. I tried the following three rubrics:
BPYTHON = type(sys.stdout).__module__.startswith('bpython')BPYTHON = 'bpython' in sys.argv[0]BPYTHON = '__console__' in sys.modulesThe first two methods work in the interactive REPL but don’t work in code loaded using the
-iflag – presumably because it runs both beforesys.stdoutand friends have been wrapped, and beforesys.argvhas been mutated. The last method does seem to work, but it feels extremely janky and fragile and I don’t trust it to survive the next volley of bpython internals-refactoring.So: can we get an officially-sanctioned method of determining that bpython is our host? That would be amazing, assuredly. It’s a great REPL, I use it every day – this’d make it even more betterer. Indeed!