A better Python REPL – bpython vs python interpreter
Key Takeaways
The video demonstrates the use of bpython, an alternative Python interpreter, and compares it to the vanilla Python interpreter, highlighting features such as syntax highlighting, auto-indentation, and autocomplete.
Full Transcript
hello this Daniel I want to show you a cool little tool and that I actually use a lot for Python development and it is called the Python and it is an alternative rep whole or alternative interpreter for the Python programming language I'm gonna show B Python to you in a minute but to give you a motivating example let's just boot up the regular Python interpreter here just in my terminal right it starts right up I can go ahead and define a little function here and I actually have to go in and fix the intonation myself and I need to remember what the print statement is called in that case the print function so yeah I want this thing to say hello to whatever the name is that gets passed in and so we're defining this here and we're gonna make it say hello Daniel run it okay it works that's pretty cool but the sad thing really is that we can't we don't get any syntax highlighting here so the this is actually really hard to read if you're used to a programming environment like sublime text or like a more fancy IDE even so this is really not that great if you're doing a lot of work in the Python repple here and then also if you're exploring a new module or new library then it's a pretty bare-bones environment for that too so let's say we want to play with the math library here and just kind of see what it has to offer pretty much have to call that their function here on it to see what the available attributes and functions are in here so let's say I'm interested in the math dot seal function to get some help on that I'd have to pretty much type all this stuff out manually and then I get the the doc string displayed and the function definition for the seal function so that kind of sucks I lose all my contacts I can't see the the other code I have on my screen here and it's not super awesome it gets a job done it can be made better with some tweaks to give you autocomplete but really not much beyond that so we're going to quit that interpreter by hitting ctrl D and drop back to the shell and so what I'm going to show you now is this alternative interpreter that it's called B Python and it's pretty much the same thing as Python was before but it has a couple of extra features that I think make it a really really nice tool and just make playing with a Python repple a lot more enjoyable so as I work through this example again you can already tell that some things are different here first of all you get some syntax highlighting here so we can see that the different tokens in that line are actually also highlighted differently and get different colors which is really awesome and much much much easier on the eyes we also get a feature that does highlighting for matching parentheses we can also be handy if you're editing like a really long string with nested parentheses and the good news is it actually does the indentation automatically for us this time so as I go ahead and type out my print function here I can actually use the autocomplete that is also offered by B Python so I can just hit the tab key and it'll run through the different options that were offered here and now I can just keep on going and I saved a couple of characters typing this out the other really cool thing is is if I make a syntax error in here so let's say we're using you know the wrong kind of parentheses to complete that line I get the the syntax error printed out and I can tell okay something went wrong the cool thing is now that I can hit ctrl R to rewind that last action and it'll even show up here in my history as this kind of ghosted line here and I can just fix my syntax error and then commit that and I've now defined that say hello function successfully you can give it the same the same example here and what's also really cool is that just to show it works as I type this out you can see that I get the function definition for this again and if it has a doc string it would also show the doc string so let's clear that out the other cool thing that I find really helpful is the autocomplete and help functionality for exploring modules or just kind of seeing what modules have to offer so let's import the math module again and again here you can tell it even does autocomplete frees modules as I type out em and then a and then T it kind of narrows down to autocomplete until only math it's left and can import it right away so now where previously I have to use the dur function I can just go and type out math and input a dot and the autocomplete shows me all of the symbols or I guess functions and attributes it finds in there that I can then reference so let's say we're looking for the seal function it's just autocomplete adhere type and open parentheses and now I actually get the function definition and the dock string for that displayed in line so I don't lose any of my my context here I know exactly what I typed before and I can learn all about that is to know about the seal function and then we're just gonna call it passing a value yeah numbers get highlighted differently too and I think that is really really awesome and the good news is you it doesn't require any configuration at all like once you've installed it you're you're done and you don't have to fiddle with any interpreter config files to get the functionality that I've just shown you so again we're gonna quit this now and I want to show you real quick how you can install B Python if you haven't if you haven't installed it already alright so you just go ahead and do a pip install B Python I recommend using sudo for it because then it becomes available globally so this can be handy in some situations obviously if you're using a virtual end of 10 it's probably better to put it in there but that command will get you started so if you run that it'll ask you for your root password and obviously I already had it installed but then you're ready to go and you can jump right in and play with B Python yeah let me know how that worked for you and say hi on Twitter if you if you enjoyed that and want to talk about this stuff all right take care
Original Description
https://dbader.org/python-tricks ► Master Python with short & sweet productivity tips and code snippets
A quick Python tutorial video that demonstrates "bpython", an awesome alternative Python interpreter.
Compared to the vanilla Python interpreter bpython knows a few extra tricks like: syntax highlighting, auto indent (yay!), and auto completion.
Bpython is somewhat similar to the IPython REPL, but personally I like it better. It's nimble and fast and a joy to program with.
Check it out, it’s a really great tool!
FREE COURSE – "5 Thoughts on Mastering Python" https://dbader.org/python-mastery
SUBSCRIBE TO THIS CHANNEL: https://dbader.org/youtube
* * *
► Python Developer MUGS, T-SHIRTS & MORE: https://nerdlettering.com
FREE Python Coding Tutorials & News:
» Python Tutorials: https://dbader.org
» Python News on Twitter: https://twitter.com/@dbader_org
» Weekly Tips for Pythonistas: https://dbader.org/newsletter
» Subscribe to this channel: https://dbader.org/youtube
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Real Python · Real Python · 1 of 60
← Previous
Next →
▶
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
A better Python REPL – bpython vs python interpreter
Real Python
Introducing large-type.com – A Utility Website
Real Python
Reading Hacker News Without Wasting Tons of Time
Real Python
Forward References and Python 3 Type Hints
Real Python
Using Sublime Text as your Git Editor
Real Python
Python Code Linting and Auto-Complete for Sublime Text
Real Python
Make your Python Code More Readable with Custom Exceptions
Real Python
Write Better Tests with Sublime Text's Split Layout Feature
Real Python
How to Use Sublime Text from the Command Line
Real Python
Rename Variables with Multiple Selection in Sublime Text
Real Python
Sublime Text Settings for Writing PEP 8 Python
Real Python
Write Cleaner Python with Sublime Text's Indent Guides
Real Python
Sublime Text Whitespace Settings for Python Development
Real Python
Function Argument Unpacking in Python
Real Python
Python Code Review: Debugging and Refactoring "Conway's Game of Life" + Automated Tests
Real Python
Using "get()" to Return a Default Value from a Python Dict
Real Python
A Python Shorthand for Swapping Two Variables
Real Python
Python Code Review: Refactoring a Web Scraper, PEP 8 Style Guide Compliance, requirements.txt
Real Python
Click & Jump to Test Failures from the Command Line (iTerm2)
Real Python
Setting up Sublime Text for Python Developers
Real Python
Sublime Text + Python Guide Overview
Real Python
Python Code Review: Adding Pytest Tests to an Existing Python Web Scraper
Real Python
Type-Checking Python Programs With Type Hints and mypy
Real Python
A Shorthand for Merging Dictionaries in Python 3.5+
Real Python
Python Code Review Flask Web Security Tutorial + Virtualenvs, requirements.txt
Real Python
My Python Code Looks Ugly and Confusing – Help!
Real Python
Setting Up a Programmer Portfolio/Developer Blog – How To Get Started
Real Python
Do I Need a GitHub/GitLab/Bitbucket Profile as a Developer?
Real Python
Programmer Portfolio – Example and Walkthrough
Real Python
How to Get Your 1st Speaking Gig at a Tech Conference
Real Python
How to Build Your Public Speaking Skills as a Developer
Real Python
The Object-oriented Version of "Spaghetti Code" is "Lasagna Code" ?!
Real Python
Setting up Sublime Text for Python Developers – Lesson #1
Real Python
Cool New Features in Python 3.6
Real Python
"is" vs "==" in Python – What's the Difference? (And When to Use Each)
Real Python
Emulating switch/case Statements in Python with Dictionaries
Real Python
Python Function Argument Unpacking Tutorial (* and ** Operators)
Real Python
What Code Should I Put On My GitHub/GitLab/BitBucket Profile?
Real Python
A Crazy Python Dictionary Expression ?!
Real Python
String Conversion in Python: When to Use __repr__ vs __str__
Real Python
Method Types in Python OOP: @classmethod, @staticmethod, and Instance Methods
Real Python
Optional Arguments in Python With *args and **kwargs
Real Python
Python Context Managers and the "with" Statement (__enter__ & __exit__)
Real Python
Installing Python Packages with pip and virtualenv / venv
Real Python
"For Each" Loops in Python with enumerate() and range()
Real Python
Python Code Review: LibreOffice Automation and the Python Standard Library
Real Python
Managing Python Dependencies With Pip and Virtual Environments – Lesson #1
Real Python
Python Tutorial: List Comprehensions Step-By-Step
Real Python
Leveraging Python's Implicit "return None" Statements
Real Python
What's the meaning of underscores (_ & __) in Python variable names?
Real Python
Python Data Structures: Sets, Frozensets, and Multisets (Bags)
Real Python
Writing automated tests for Python command-line apps and scripts
Real Python
How to find great Python packages on PyPI, the Python Package Repository
Real Python
Immutable vs Mutable Objects in Python
Real Python
PyPI vs Warehouse, the Next-Generation Python Package Repository
Real Python
pep8.org — The Prettiest Way to View the PEP 8 Python Style Guide
Real Python
My Experience at PyCon 2017 in Portland
Real Python
Pylint Tutorial – How to Write Clean Python
Real Python
"Reverse a List in Python" Tutorial: Three Methods & How-to Demos
Real Python
Python Refactoring: "while True" Infinite Loops & The "input" Function
Real Python
🎓
Tutor Explanation
DeepCamp AI