#231 Go Python, Go!

Watch the live stream: Watch on YouTube About the show Sponsored by us! Support our work through: Our courses at Talk Python Training pytest book Patreon Supporters Special guests: Cecil Phillip Brian #1: For-Else: A Weird but Useful Feature in Python Yang Zhou After a for loop, you can put an else block. The else block only executes when there is no break in the loop. If the loop got all the way to the end, and off the end, the else block will run. First, I’m not used to putting break or else anywhere in my Python code, so I’m also curious why you’d want to do this. Yang explains the feature, then talks about 3 scenarios for use: Iterate and find items without needing a flag variable. break when you find what you are looking for, and the else only runs if you didn’t find it. Help to break out of nested loops I’m still confused by this one Help to handle exceptions Kind of a cool use. try/except in a for loop. Have a break in the except block. Then the else block will be fore code where you know no exceptions were caught. Take away: The first reason wins it for me. I hate it when I feel I need to add a “found” flag to some code. else seems cleaner. Also: Please add comments to else blocks. Many people won’t know how they work, so a short explanation can help tons. Michael #2: Tortoise ORM Familiar asyncio ORM for python, built with relations in mind I’ve seen this ORM popping up around the async web stories a lot these days Similar to Django’s ORM Tortoise ORM is supported on CPython >= 3.7 for SQLite, MySQL and PostgreSQL. They offer a nice, broad perf comparison on their github page Really nice and clean API for ORM things, again on the github page Tortoise ORM uses Aerich as database migrations tool Cecil #3: Faster Python with Go Shared objects Leverage Go's standard library and ecosystem in Python Language interop is a good for productivity Passing data is limited to primitive types Brian #4: Learn by reading code: Python standard library design decisions explained (for advanced beginners) Reading code is a great way to improve your own coding. What code should you read? If it’s great code, you could improve. If it’s scary code, it might not be so good, and might teach you bad practices Python stdlib is there and has some interesting features: all of the code is available PEPs are available so you can read the discussions that went into it while you are reading the code, or before This is huge. Most code you’ll find, even within companies, doesn’t have “why we did this” explanations. However… it is not uniform different authors some is old, and pythonic was different 10-20 years ago lots of code around to preserve backwards compatibility So here’s some recommendations: statistics : code is simple, well documented, PEP has design decisions and comparisons pathlib: good object-oriented example, good comparative study, as you can also read os.path dataclasses: extremely well documented, good example of dataclasses graphlib: does one thing, an implementation of a topological sort algorithm. no PEP, but an issue with a discussion thread that discusses the API decisions Related: https://devops.com/learning-curve-computer-programming-languages/ Michael #5: Gradio: Create UIs for prototyping your machine learning model in 3 minutes via David Smit Quickly create customizable UI components around your models. Gradio makes it easy for you to "play around" with your model in your browser Drag-and-drop in your own images, pasting your own text, recording your own voice, etc. and seeing what the model outputs. Gradio is useful for: Creating demos of your machine learning code for clients / collaborators / users Getting feedback on model performance from users Debugging your model interactively during development Interfaces can be easily shared publicly by setting share=True in the launch() method. Cecil #6: Use basketball stats to optimize game play with Visual Studio Code Free MS Learn learning path Inspired by Space Jam: A New Legacy Use tools like Python, Pandas, and Visual Studio Code Space Jam: A New Legacy coding workshops Extras Michael People are liking the zero analytics / perfect privacy score Joke: They said containers would fix it

Om Podcasten

Python Bytes is a weekly podcast hosted by Michael Kennedy and Brian Okken. The show is a short discussion on the headlines and noteworthy news in the Python, developer, and data science space.