Title: Inject a flag variable into the global namespace to indicate to a script that it’s running inside bpython · Issue #795 · bpython/bpython · GitHub
Open Graph Title: Inject a flag variable into the global namespace to indicate to a script that it’s running inside bpython · Issue #795 · bpython/bpython
X Title: Inject a flag variable into the global namespace to indicate to a script that it’s running inside bpython · Issue #795 · bpython/bpython
Description: 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__ to True. This allows for trivial tests like e...
Open Graph Description: 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__ to Tr...
X Description: 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__ to Tr...
Opengraph URL: https://github.com/bpython/bpython/issues/795
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inject a flag variable into the global namespace to indicate to a script that it’s running inside bpython","articleBody":"It would be very advantageous if one could easily discern whether or not the execution environment is bpython. \r\n\r\nFor example, in IPython, the REPL environment sets a global variable `__IPYTHON__` to `True`. This allows for trivial tests like e.g.:\r\n\r\n```python\r\ntry:\r\n __IPYTHON__\r\nexcept NameError:\r\n in_ipython = False\r\nelse:\r\n in_ipython = True\r\n```\r\n\r\nContrastingly, 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:\r\n\r\n1. `BPYTHON = type(sys.stdout).__module__.startswith('bpython')`\r\n2. `BPYTHON = 'bpython' in sys.argv[0]`\r\n3. `BPYTHON = '__console__' in sys.modules`\r\n\r\nThe first two methods work in the interactive REPL but don’t work in code loaded using the `-i` flag – presumably because it runs both before `sys.stdout` and friends have been wrapped, and before `sys.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.\r\n\r\nSo: 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!","author":{"url":"https://github.com/fish2000","@type":"Person","name":"fish2000"},"datePublished":"2020-02-04T13:21:50.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/795/bpython/issues/795"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:032f8f47-bcc5-c97f-7e56-c578a4b7e91a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AC26:3ED417:E46BB:14274A:6968E734 |
| html-safe-nonce | 444d75135bf31b2ced1c34c266a169ac08568845cd572ee93d4654f2933a9d79 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzI2OjNFRDQxNzpFNDZCQjoxNDI3NEE6Njk2OEU3MzQiLCJ2aXNpdG9yX2lkIjoiOTEzNzg1OTQyODczODQ1OTQ0NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0945388796642dfb5d1e89d1009f37b39b8131fce1cec8b5a29f9447bcfd368e |
| hovercard-subject-tag | issue:559715940 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/bpython/bpython/795/issue_layout |
| twitter:image | https://opengraph.githubassets.com/22d09fbfd3c5746988205db172d2f939c39a789b7e0eafc5507ff07b53594297/bpython/bpython/issues/795 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/22d09fbfd3c5746988205db172d2f939c39a789b7e0eafc5507ff07b53594297/bpython/bpython/issues/795 |
| og:image:alt | 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__ to Tr... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fish2000 |
| hostname | github.com |
| expected-hostname | github.com |
| None | b5416305695900bdab7d289f90ea3d96bf36397112f2ab16f5a5a120f38de085 |
| turbo-cache-control | no-preview |
| go-import | github.com/bpython/bpython git https://github.com/bpython/bpython.git |
| octolytics-dimension-user_id | 8071396 |
| octolytics-dimension-user_login | bpython |
| octolytics-dimension-repository_id | 21508865 |
| octolytics-dimension-repository_nwo | bpython/bpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 21508865 |
| octolytics-dimension-repository_network_root_nwo | bpython/bpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 366035abf3d5b1e31841c97e2fa2ce02a3007a7b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width