Share Your REPL Session
00:00 Share Your REPL Session. The bpython REPL is an excellent teaching tool that you can use to explain an idea and then share the resulting code with your coworkers or students in a classroom. After you’ve written something in bpython, you can copy the entire REPL session with all outputs to the clipboard, save it in a file, or share it online.
00:23 You can copy the contents of your REPL session to the clipboard with a single keystroke, which can be handy for sharing code snippets with others or pasting them into a forum online. Note, however, that the copy-to-clipboard feature doesn’t work by default in bpython.
00:55 Once it’s installed, press F10, which is the default shortcut to grab your REPL session. Here, a familiar function is created and used a couple of times. F10 is pressed, which copies the session to the clipboard.
01:19 The code is pasted in from the clipboard, complete with comments for the lines where the output was present, and can be saved for use elsewhere. If you want to share the code in a visual manner, including code coloring, then be sure to open it in an appropriate editor.
01:37 There is another option available to you. Instead of pasting the code by hand into a messaging application or text editor, you can save your current REPL session directly to a local file on your computer.
02:02 It will ask you to type the filename to be created in the current working directory or an entire path indicating where you want it to be saved. If the file already exists, then you’ll have the option to overwrite it, append to it, or cancel the operation.
02:21 On some UNIX shells, the Ctrl + S key combination is a standard hotkey reserved for stopping the output of a running program. It sends a special code to pause the transmission of data through the terminal, overriding bpython’s default behavior.
03:15 This makes code easier to run. However, you still have to send the file as an attachment yourself if you want to share the code with others, and that’s where sending your REPL session to a pastebin comes in handy.
03:29 The third way of sharing code in bpython is to upload your REPL session to a pastebin or an online text storage service. The bpython REPL supports bpa.st by default, which is an instance of pinnwand, but you can change the default pastebin to another service if you want to. When you hit F8 and confirm your choice with Y, after a few moments, you’ll be presented with a publicly available URL to share.
04:04 As an owner, you’ll also get another URL, which you can use to delete the paste if you no longer want it on the server. If you don’t delete the paste yourself, then the URL will expire after one week.
04:17 You can change this default setting in bpython’s configuration. When someone navigates to your paste, they’ll see a nicely formatted snapshot of your bpython REPL session with syntax highlighting and the ability to toggle the dark mode.
Become a Member to join the conversation.