Sponsored by Datadog: pythonbytes.fm/datadog
Special guest: Jeremy Tanner
Watch on YouTube
Brian #1: Constant Folding in Python
- Arpit Bhayani
- Constant Folding is when a language replaces constant expressions at compile time rather than computing them at runtime.
- CPython does this while creating the bytecode.
- We can use
dis to see it in action
>>> import dis
>>> dis.dis("day_sec = 24 * 60 * 60")
1 0 LOAD_CONST 0 (86400)
2 STORE_NAME 0 (day_sec)
4 LOAD_CONST 1 (None)
- Python tries to fold lots of constants, but not all.
- Seems to be based on size
>>> x = 2 ** 64 # folded
>>> x = 4 ** 64 # not folded
>>> a = "-" * 4096 # folded
>>> a = "-" * 4097 # not folded
- Discussion continues with a discussion of how CPython folding is implemented recursively and elegantly.
- Key takeaway for me:
- Remember to not try to pre-compute constants while coding.
- Make them easy to read and Python will handle the optimization for you.
Michael #2: Update All Packages With pip-review
- via PyCoders
- Updating Python packages can be a hassle.
- There are many of them - it's hard to keep track of all the newest versions
- When you decide what to update, you still have to update each of them manually.
- Originally a part of the
pip-tools package, it now lives on as a standalone convenience wrapper around
(venv) $ pip install pip-review
scikit-learn==0.23.2 is available (you have 0.23.1)
scipy==1.5.4 is available (you have 1.4.1)
seaborn==0.11.0 is available (you have 0.10.1)
- Once you've identified if you'd like to update your packages, you can update them all, automatically, using
- Limit with constraints.txt file
- Can do it interactively via
Jeremy #3: Quantum Mechanical Keyboard Firmware
- How does the Python get into your computer? Much of it, through the keyboard
- Why mechanical keyboards?
- Where is QWERTY from?
- And when?
- and because it’s essentially an escape room built of hardware and open source software and dodgy international transactions
- I’ve fallen further down the mechanical keyboard rabbit hole
- Keyboard firmware is mostly written in c
- But there are Python portions
- So the CLI is Python, where else is Python?
- When looking to improve your keymap, key logging w/ Python to process logs for heatmaps
Brian #4: Reinventing the Python Logo
- Carlo Occhiena interview with Jessica Williamson
- Some cool logo history
Current, from 2006, designed by Tim Parklin
“The logo is actually based on mayan representations of snakes which very often represent only the head and perhaps a short length of tail. The structure of the snake representations the natural coiling/nesting of a snake as seen side on.” - Tim Parklin
Jessica Williamson proposed a new one in 2020:
Then there’s the rest of the article talking about the design process, etc.
- But….. just wanted to throw this out there. I’m happy with the 2006 version. - Brian
- MK: Have you ever seen the logos on the app stores?
Michael #5: Private PyPI with Serverless Computing
- Project: aws-lambda-pypi
- Brings together a few pieces so you can easily run a small PyPICloud instance as an AWS Lambda function with the help of Terraform.
- PyPICloud lets you publish Python packages privately.
- AWS Lambda lets you run a small service for free.
- Terraform ensures the service is deployed and maintained correctly.
- Security: This project takes the following security precautions.
- The session keys are auto-generated and stored in a secret.
- The server configuration file, which contains the session keys, is generated on the fly to minimize the possibility of exposure.
- The lambda function runs with a role limited to accessing only what it needs.
- PyPICloud is configured to display no packages to unauthenticated users.
Jeremy #6: Beyond the Basic Stuff w/Python
- Al Sweigart
- Want to become less feral?