Skip to content

Instantly share code, notes, and snippets.

@sevko
Last active December 21, 2021 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sevko/f07e5807bbdd0d849294 to your computer and use it in GitHub Desktop.
Save sevko/f07e5807bbdd0d849294 to your computer and use it in GitHub Desktop.
Parallel versions of bpython for Python 2 and 3.

bpython+

bpython+ is a thin wrapper around the bpython interpreter, which allows the user to specify whether it should be executed with version 2 or 3 of the Python interpreter; the implementation is practically identical to that of pylint+.

requirements

You must have:

  • python2 in your $PATH
  • python3 in your $PATH
  • bpython installed (via pip, and not from your package manager) for Python 2
  • pylint installed (via pip3, and not from your package manager) for Python 3

use

Place bpython+ somewhere in your $PATH, and make sure that it has executable permissions. Then:

bpython+ 2|3 [BPYTHON_ARGS]

For instance:

$ bpython+ 2
>>> import sys
>>> sys.version_info
sys.version_info(major=2, minor=7, micro=6, releaselevel='final', serial=0)

$ bpython+ 3
>>> import sys
>>> sys.version_info
sys.version_info(major=3, minor=4, micro=0, releaselevel='final', serial=0)
#! /usr/bin/env bash
# Description:
# A wrapper around bpython that allows the user to specify whether it should
# be executed with version 2 or 3 of the Python interpreter.
#
# Use:
# bpython+ PYTHON_VERSION [BPYTHON_ARGS]
#
# PYTHON_VERSION: Either 2 or 3, for version 2/3 of the Python interpreter.
# BPYTHON_ARGS: Argument to pass on to bpython.
python_interpreter="python${1}"
bpython_args="${@:2}"
bpython_import=$(cat << PYTHON
import sys
import pkg_resources
__requires__ = "bpython"
sys.exit(
pkg_resources.load_entry_point("bpython", "console_scripts", "bpython")()
)
PYTHON
)
$python_interpreter -c "$bpython_import" $bpython_args
@aquablast
Copy link

aquablast commented Dec 21, 2021

On Linux shell it may be simpler. For example, on bash follow the steps below for your user:

  • Install bpython by pip2 and pip3;
  • Add rows to end of .bashrc file:
    alias bpython2='python2 -m bpython'
    alias bpython3='python3 -m bpython'
    In my case, i set the 'bpy'-named aliases
  • Run as non-priveileged user:
    $ . .bashrc

That's all:
bpython

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment