Wednesday, April 28, 2021

Python Bytes: #231 Go Python, Go!

<p><strong>Watch the live stream:</strong></p> <a href='https://www.youtube.com/watch?v=rDYKZG6Fn8o' style='font-weight: bold;'>Watch on YouTube</a><br> <br> <p><strong>About the show</strong></p> <p>Sponsored by us! Support our work through:</p> <ul> <li>Our <a href="https://training.talkpython.fm/"><strong>courses at Talk Python Training</strong></a></li> <li><a href="https://pragprog.com/titles/bopytest/python-testing-with-pytest/"><strong>pytest book</strong></a></li> <li><a href="https://www.patreon.com/pythonbytes"><strong>Patreon Supporters</strong></a></li> </ul> <p>Special guests: </p> <ul> <li><a href="https://twitter.com/cecilphillip"><strong>Cecil Phillip</strong></a></li> </ul> <p><strong>Brian #1:</strong> <a href="https://medium.com/techtofreedom/for-else-a-weird-but-useful-feature-in-python-2076d8dafad1"><strong>For-Else: A Weird but Useful Feature in Python</strong></a></p> <ul> <li>Yang Zhou</li> <li>After a <code>for</code> loop, you can put an <code>else</code> block.</li> <li>The <code>else</code> block only executes when there is no <code>break</code> in the loop. If the loop got all the way to the end, and off the end, the <code>else</code> block will run.</li> <li>First, I’m not used to putting <code>break</code> or <code>else</code> anywhere in my Python code, so I’m also curious why you’d want to do this.</li> <li>Yang explains the feature, then talks about 3 scenarios for use: <ul> <li>Iterate and find items without needing a flag variable. </li> <li><code>break</code> when you find what you are looking for, and the <code>else</code> only runs if you didn’t find it.</li> <li>Help to break out of nested loops <ul> <li>I’m still confused by this one</li> </ul></li> <li>Help to handle exceptions <ul> <li>Kind of a cool use. try/except in a <code>for</code> loop. Have a <code>break</code> in the <code>except</code> block. Then the <code>else</code> block will be fore code where you know no exceptions were caught.</li> </ul></li> </ul></li> <li>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. <code>else</code> seems cleaner.</li> <li>Also: Please add comments to <code>else</code> blocks. Many people won’t know how they work, so a short explanation can help tons.</li> </ul> <p><strong>Michael #2:</strong> <a href="https://github.com/tortoise/tortoise-orm"><strong>Tortoise ORM</strong></a></p> <ul> <li>Familiar asyncio ORM for python, built with relations in mind</li> <li>I’ve seen this ORM popping up around the async web stories a lot these days</li> <li>Similar to Django’s ORM</li> <li>Tortoise ORM is supported on CPython &gt;= 3.7 for SQLite, MySQL and PostgreSQL.</li> <li>They offer a nice, broad perf comparison on their github page</li> <li>Really nice and clean API for ORM things, again on the github page</li> <li>Tortoise ORM uses <a href="https://github.com/tortoise/aerich">Aerich</a> as database migrations tool</li> </ul> <p><strong>Cecil #3:</strong> <a href="https://blog.kchung.co/faster-python-with-go-shared-objects/"><strong>Faster Python with Go Shared objects</strong></a></p> <ul> <li>Leverage Go's standard library and ecosystem in Python</li> <li>Language interop is a good for productivity</li> <li>Passing data is limited to primitive types</li> </ul> <p><strong>Brian #4:</strong> <a href="https://death.andgravity.com/stdlib"><strong>Learn by reading code: Python standard library design decisions explained (for advanced beginners)</strong></a></p> <ul> <li>Reading code is a great way to improve your own coding.</li> <li>What code should you read? <ul> <li>If it’s great code, you could improve.</li> <li>If it’s scary code, it might not be so good, and might teach you bad practices</li> </ul></li> <li>Python stdlib is there and has some interesting features: <ul> <li>all of the code is available</li> <li>PEPs are available so you can read the discussions that went into it while you are reading the code, or before</li> <li>This is huge. Most code you’ll find, even within companies, doesn’t have “why we did this” explanations.</li> </ul></li> <li>However… <ul> <li>it is not uniform</li> <li>different authors</li> <li>some is old, and pythonic was different 10-20 years ago</li> <li>lots of code around to preserve backwards compatibility</li> </ul></li> <li>So here’s some recommendations: <ul> <li>statistics : code is simple, well documented, PEP has design decisions and comparisons</li> <li>pathlib: good object-oriented example, good comparative study, as you can also read os.path</li> <li>dataclasses: extremely well documented, good example of dataclasses</li> <li>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</li> </ul></li> </ul> <p>Related: https://ift.tt/2R8HeKW> <p><img src="https://ift.tt/3u8eCjW" alt="" /></p> <p><strong>Michael #5:</strong> <a href="https://www.gradio.app/"><strong>Gradio: Create UIs for prototyping your machine learning model in 3 minutes</strong></a></p> <ul> <li>via David Smit</li> <li>Quickly create customizable UI components around your models.</li> <li>Gradio makes it easy for you to "play around" with your model in your browser</li> <li>Drag-and-drop in your own images, pasting your own text, recording your own voice, etc. and seeing what the model outputs.</li> <li>Gradio is useful for:</li> <li>Creating demos of your machine learning code for clients / collaborators / users</li> <li>Getting feedback on model performance from users</li> <li>Debugging your model interactively during development</li> <li>Interfaces can be easily shared publicly by setting <code>share=True</code> in the <code>launch()</code> method.</li> </ul> <p><strong>Cecil #6:</strong> <a href="https://docs.microsoft.com/en-us/learn/paths/optimize-basketball-games-with-machine-learning/">Use basketball stats to optimize game play with Visual Studio Code</a></p> <ul> <li>Free MS Learn learning path</li> <li>Inspired by Space Jam: A New Legacy</li> <li>Use tools like Python, Pandas, and Visual Studio Code </li> <li><a href="https://www.microsoft.com/whatsinstore/2020/12/14/space-jam-a-new-legacy-coding-workshops-let-kids-team-up-with-lebron-bugs-bunny">Space Jam: A New Legacy coding workshops</a></li> </ul> <p><strong>Extras</strong></p> <p><strong>Michael</strong></p> <ul> <li><a href="https://twitter.com/TalkPython/status/1384943094899122177"><strong>People are liking</strong></a> the zero analytics / perfect privacy score</li> </ul> <p><strong>Joke:</strong> <a href="https://devhumor.com/media/linux-containers-and-kubernetes-for-beginners"><strong>They said containers would fix it</strong></a></p> <p><img src="https://ift.tt/3nzOFaf" alt="" /></p>

from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...