The Invent with Python Blog

Writings from the author of Automate the Boring Stuff.

Tue 28 March 2023

Book Review: Python Distilled

Posted by Al Sweigart in python   

5 stars. Python Distilled has a perfectly suited title: This book is for experienced programmers who want to learn Python and need the Python programming language's core syntax, standard library, and Pythonic idioms. However, if you're a developer who wants to add Python to your toolbox, I recommend Python Distilled as one of the first books you should read.

Read more...




Sun 20 November 2022

How to Run Pip From The Python Interactive Shell with pipfromrepl

Posted by Al Sweigart in python   

If you are an instructor leading a Python programming workshop, getting third-party PyPI packages installed on students' machines with pip has several hurdles: navigating the command-line, operating system differences, distinguishing between pip and pip3, dealing with multiple versions of Python, misconfigured PATH environment variables, and virtual environments are all possible pitfalls.

You can avoid all of this and save time by using pipfromrepl, which allows you to install PyPI packages from the interactive shell. These same steps work no matter what the computer's Python setup is.

Read more...


Sat 19 November 2022

Python Linter Comparison 2022: Pylint vs Pyflakes vs Flake8 vs autopep8 vs Bandit vs Prospector vs Pylama vs Pyroma vs Black vs Mypy vs Radon vs mccabe

Posted by Al Sweigart in python   

As you can tell from the lengthy title, there are many linting tools for Python. Some of them have near-identical names as each other. In November 2022, I upgraded my text editor to Sublime Text 4 and then took the opportunity to spend a few hours reviewing all of the Python linters I could find. After personally reviewing all of them, I've selected the following as must-haves: Pyflakes, Mypy, and Black. If you'd like additional tools, I also liked: Radon, Pyroma, and docformatter. I'm using Python 3.12.0. I don't care for my linter to point out when I stray from the certain dictates in the PEP 8 document, and my linter choices reflect that. You might have different needs and values than I, so in this blog post I give my reasoning and views for each linter.

Read more...



Mon 31 October 2022

Installing Brython to Get Python in Your Browser

Posted by Al Sweigart in python   

JavaScript is not the only programming language you can run in the browser. Brython is a Python interpreter implemented in JavaScript so you can run Python code in your browser. This lets you have a Python interactive shell without having to install Python. You can also write Python code to interact with the DOM and create browser apps just like you could with JavaScript. The primary downside is that a browser must download about 6 megabytes of JavaScript files before it can run, which can be a significant delay. This blog post guides you through setting up Brython.

Read more...


Sun 30 October 2022

17 Online Python IDEs and Interactive Shells/REPLs

Posted by Al Sweigart in python   

Installing Python is easy, but maybe you're on a smartphone/tablet, are on a library computer that doesn't let you install software, or can't install Python for some other reason. This article has a list of 10 free Python interpreters and interactive shells (also called REPLs) that you can access from a web browser.

Read more...


Sat 29 October 2022

How Computers Store Data with Binary Numbers

Posted by Al Sweigart in misc   

Programming and hacking in movies often involves streams of ones and zeros flowing across the screen. This looks mysterious and impressive, but what do these ones and zeros actually mean? You're probably aware that binary numbers (numbers written using only the two digits, zero and one) have something to do with computers but don't know why.

Read more...



Thu 25 August 2022

How to Run Pip From The Python Interactive Shell

Posted by Al Sweigart in python   

Installing Python modules with the pip tool is surprisingly hard to describe to beginners learning to code. There are several potential issues: multiple Python installations, virtual environments, PATH environment variable settings. You have to introduce command-line terminals and file system navigation, and the differences between Windows and Mac/Linux. However, there is a line of code you can run from the interactive shell to handle all this for you.

Read more...


Tue 23 August 2022

Introducing Humre: Human-Readable Regular Expressions

Posted by Al Sweigart in python   

Regular expressions (aka regexes) are a mini-language to specify a pattern of text to look for. However, regex syntax is composed of various punctuation marks that can be hard to remember. Humre is a Python module that gives a more human-readable syntax that works better with code editing tools. You can install Humre just like any other Python module with pip install humre and the full documentation is available in the git repo's README file.

Read more...



Tue 09 August 2022

New Book: The Recursive Book of Recursion by Al Sweigart

Posted by Al Sweigart in news   

My new programming book, the Recursive Book of Recursion, is released in August 2022. The book covers several classic recursive algorithms and breaks down recursion's fearsome reputation as a programming technique. The book has the code for its numerous programs in both Python and JavaScript. When you buy it direct from the publisher, No Starch Press, you'll receive a DRM-free ebook copy with your print book order.

Read more...