Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Inject a flag variable into the global namespace to indicate to a script that it’s running inside bpython #795

Open
@fish2000

Description

@fish2000

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.:

try:__IPYTHON__exceptNameError:in_ipython=Falseelse:in_ipython=True

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:

  1. BPYTHON = type(sys.stdout).__module__.startswith('bpython')
  2. BPYTHON = 'bpython' in sys.argv[0]
  3. BPYTHON = '__console__' in sys.modules

The first two methods work in the interactive REPL but don’t work in code loaded using the-i flag – presumably because it runs both beforesys.stdout and friends have been wrapped, and beforesys.argv has 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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp