Planet Python
Last update: April 29, 2024 09:43 PM UTC
April 29, 2024
Zero to Mastery
Python Monthly Newsletter đ»đ
53rd issue of Andrei Neagoie's must-read monthly Python Newsletter: Whitehouse Recommends Python, Memory Footprint, Let's Talk About Devin, and much more. Read the full newsletter to get up-to-date with everything you need to know from last month.
PyCon
Meet PyCon US Keynote Speakers
We canât wait to welcome Jay Miller, Kate Chapman, Simon Willison, and Sumana Harihareswara to our stage as PyCon US keynote speakers this year.
We asked each of our keynote speakers:
What excites them about the Python community?
What theyâre looking forward to doing at PyCon US?
What can we expect from their keynote speech?
And any advice theyâd like to share with the Python community.
Check out our interviews with each of our keynote speakers below!
Jay Miller
"I fully believe I owe my entire tech career to the Python community. I met so many amazing people that I would become long lasting friends with."
Kate Chapman
"I'm excited to connect with people who are passionate about free and open source software and to learn about technologies that I haven't spent much time with."
Simon Willison
"Take advantage of the fact that so many people from the worldwide Python community are in the same place at the same time for just a couple of days. Everybody here wants to talk to you. And you should assume that anyone who you think is interesting will find you interesting as well and will want to hear from you."Sumana Harihareswara
"I do stand-up comedy and theater. I take it seriously, my responsibility to educate and entertain if you're sitting in front of me for 40 minutes."
Register Now
Donât miss out on meeting our keynote speakers in person! Register now for PyCon US before we sell out. As a note, some of our tutorials are already sold out, as well as our hotel room blocks. There are only a few short weeks left before the conference, so donât wait, register today!
Stay in the Loop
The PyCon US website has all the information you need to know about attending our conference. In order to catch all the latest news, be sure to:
- Subscribe to the PyCon US Blog
- Follow @PyCon and @thePSF on Twitter/X
- Follow @pycon@fosstodon.org and @ThePSF@fosstodon.org on Mastodon,
- The PSF on LinkedIn
- And subscribe to PyCon US 2024 News!
Engage with our community on social media by using our official hashtag: #PyConUS.
Thank you for supporting the Python community. We canât wait to meet you all in Pittsburgh in a few short weeks!Real Python
Python's unittest: Writing Unit Tests for Your Code
The Python standard library ships with a testing framework named unittest
, which you can use to write automated tests for your code. The unittest
package has an object-oriented approach where test cases derive from a base class, which has several useful methods.
The framework supports many features that will help you write consistent unit tests for your code. These features include test cases, fixtures, test suites, and test discovery capabilities.
In this tutorial, youâll learn how to:
- Write
unittest
tests with theTestCase
class - Explore the assert methods that
TestCase
provides - Use
unittest
from the command line - Group test cases using the
TestSuite
class - Create fixtures to handle setup and teardown logic
To get the most out of this tutorial, you should be familiar with some important Python concepts, such as object-oriented programming, inheritance, and assertions. Having a good understanding of code testing is a plus.
Free Bonus: Click here to download the free sample code that shows you how to use Pythonâs unittest to write tests for your code.
Take the Quiz: Test your knowledge with our interactive âPython's unittest: Writing Unit Tests for Your Codeâ quiz. Youâll receive a score upon completion to help you track your learning progress:
Interactive Quiz
Python's unittest: Writing Unit Tests for Your CodeIn this quiz, you'll test your understanding of Python testing with the unittest framework from the standard library. With this knowledge, you'll be able to create basic tests, execute them, and find bugs before your users do.
Testing Your Python Code
Code testing or software testing is a fundamental part of a modern software development cycle. Through code testing, you can verify that a given software project works as expected and fulfills its requirements. Testing enforces code quality and robustness.
Youâll do code testing during the development stage of an application or project. Youâll write tests that isolate sections of your code and verify its correctness. A well-written battery or suite of tests can also serve as documentation for the project at hand.
Youâll find several different concepts and techniques around testing. Most of them surpass the scope of this tutorial. However, unit test is an important and relevant concept. A unit test is a test that operates on an individual unit of software. A unit test aims to validate that the tested unit works as designed.
A unit is often a small part of a program that takes a few inputs and produces an output. Functions, methods, and other callables are good examples of units that youâd need to test.
In Python, there are several tools to help you write, organize, run, and automate your unit test. In the Python standard library, youâll find two of these tools:
doctest
unittest
Pythonâs doctest
module is a lightweight testing framework that provides quick and straightforward test automation. It can read the test cases from your projectâs documentation and your codeâs docstrings. This framework is shipped with the Python interpreter as part of the batteries-included philosophy.
Note: To dive deeper into doctest
, check out the Pythonâs doctest: Document and Test Your Code at Once tutorial.
The unittest
package is also a testing framework. However, it provides a more complete solution than doctest
. In the following sections, youâll learn and work with unittest
to create suitable unit tests for your Python code.
Getting to Know Pythonâs unittest
The unittest
package provides a unit test framework inspired by JUnit, which is a unit test framework for the Java language. The unittest
framework is directly available in the standard library, so you donât have to install anything to use this tool.
The framework uses an object-oriented approach and supports some essential concepts that facilitate test creation, organization, preparation, and automation:
- Test case: An individual unit of testing. It examines the output for a given input set.
- Test suite: A collection of test cases, test suites, or both. Theyâre grouped and executed as a whole.
- Test fixture: A group of actions required to set up an environment for testing. It also includes the teardown processes after the tests run.
- Test runner: A component that handles the execution of tests and communicates the results to the user.
In the following sections, youâll dive into using the unittest
package to create test cases, suites of tests, fixtures, and, of course, run your tests.
Organizing Your Tests With the TestCase
Class
The unittest
package defines the TestCase
class, which is primarily designed for writing unit tests. To start writing your test cases, you just need to import the class and subclass it. Then, youâll add methods whose names should begin with test
. These methods will test a given unit of code using different inputs and check for the expected results.
Hereâs a quick test case that tests the built-in abs()
function:
Read the full article at https://realpython.com/python-unittest/ »
[ Improve Your Python With đ Python Tricks đ â Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]
Nikola
Nikola v8.3.1 is out!
On behalf of the Nikola team, I am pleased to announce the immediate availability of Nikola v8.3.1. This release fixes some small bugs, including some introduced by the new Nikola Plugin Manager.
The minimum Python version supported is now 3.8, and we have adopted a formal policy to define the Python versions supported by Nikola.
What is Nikola?
Nikola is a static site and blog generator, written in Python. It can use Mako and Jinja2 templates, and input in many popular markup formats, such as reStructuredText and Markdown â and can even turn Jupyter Notebooks into blog posts! It also supports image galleries, and is multilingual. Nikola is flexible, and page builds are extremely fast, courtesy of doit (which is rebuilding only what has been changed).
Find out more at the website: https://getnikola.com/
Downloads
Install using pip install Nikola
.
Changes
Features
Support passing
--poll
tonikola auto
to better deal with symlink farms.
Bugfixes
Remove insecure HTTP fallback from
nikola plugin
Fix the
nikola plugin
command not working (Issue #3736, #3737)Fix
nikola new_post --available-formats
crashing with TypeError (Issue #3750)Fix the new plugin manager not loading plugins if the plugin folder is a symlink (Issue #3741)
Fix the
nikola plugin
command not working (Issue #3736)Remove no longer used leftovers of annotations support (Issue #3764)
Other
Nikola now requires Python 3.8 or newer.
Nikola has adopted a policy for Python version support, promising support for versions supported by the Python core team, Ubuntu LTS, or Debian stable, and taking into consideration Debian oldstable and PyPy.
Remove polyfill from
polyfill.io
.
Zato Blog
API Testing in Pure English
API Testing in Pure English
How to test APIs in pure English
Do you have 20 minutes to learn how to test APIs in pure English, without any programming needed?
Great, the API testing tutorial is here.
Right after you complete it, you'll be able to write API tests as the one below.
Next steps:
- Read about how to use Python to build and integrate enterprise APIs that your tests will cover
April 28, 2024
Django Weblog
Welcome our new OPS member - Baptiste Mispelon
The DSF Board are pleased to introduce Baptiste Mispelon as a new member of the ops team. Baptiste will join the team who maintains Djangoâs infrastructure.
Baptiste speaking at Django Under the Hood 2015Baptiste (IPA pronunciation /ba.tist/) is a long-time Django contributor, having been a member of the community for over a decade now.
He was an initial board member of the Django Girls Foundation, co-created the Django Under the Hood, series of conferences, and was chair of the Djangocon Europe 2016 edition. More recently, he's taken up the maintenance of Django's venerable ticket tracker: code.djangoproject.com.
He currently lives in the Norwegian countryside where he works part time as a Django developer while studying for a degree in linguistics at the local university.
You can learn more about Baptiste on his website.
Iâm also taking this time to thanks the OPS team on the behalf of the DSF board for their efforts on the maintenance during all the time of their service.
Please join me in welcoming Baptiste in the OPS team!
ListenData
Run SAS in Python without Installation
In the past few years python has gained a huge popularity as a programming language in data science world. Many banks and pharma organisations have started using Python and some of them are in transition stage, migrating SAS syntax library to Python.
Many big organisations have been using SAS since early 2000 and they developed a hundreds of SAS codes for various tasks ranging from data extraction to model building and validation. Hence it's a marathon task to migrate SAS code to any other programming language. Migration can only be done in phases so day to day tasks would not be hit by development and testing of python code. Since Python is open source it becomes difficult sometimes in terms of maintaining the existing code. Some SAS procedures are very robust and powerful in nature its alternative in Python is still not implemented, might be doable but not a straightforward way for average developer or analyst.
Do you wish to run both SAS and Python programs in the same environment (IDE)? If yes, you are not the only one. Many analysts have been desiring the same. It is possible now via python package called saspy
developed by SAS. It allows flexibility to transfer data between Pandas Dataframe and SAS Dataset. Imagine a situation when you have data in pandas dataframe and you wish to run SAS statistical procedure on the same without switching between SAS and Python environment.
Access to SAS Software for free
First and Foremost is to have access to SAS either via cloud or server/desktop version of software.
If you don't have SAS software, you don't need to worry. You can get it for free without installation via SAS OnDemand for Academics It is available for free for everyone (not restricted to students or academicians). It includes access to all the commonly used SAS modules like SAS STAT, SAS ETS, SAS SQL etc. You just need to do registration once and it does not take more than 5 minutes.
saspy python package has the following dependencies :- Python 3.4 or higher
- SAS 9.4 or higher
Steps to access SAS in Python (Jupyter)
Please follow the steps below to make SAS run in Jupyter Notebook.
To install saspy package you can run the following command in Python.
!pip install saspy
Jeremy Epstein
On FastAPI
Over the past year or two, I've been heavily using FastAPI in my day job. I've been around the Python web framework block, and I gotta say, FastAPI really succeeds in its mission of building on the strengths of its predecessors (particularly Django and Flask), while feeling more modern and adhering to certain opinionated principles. In my opinion, it's pretty much exactly what the best-in-breed of the next logical generation of web frameworks should look like.
ÂĄĂndale, ĂĄndale, arriba!Image source: The Guardian
Let me start by lauding FastAPI's excellent documentation. Having a track record of rock-solid documentation, was (and still is!) – in my opinion – Django's most impressive achievement, and I'm pleased to see that it's also becoming Django's most enduring legacy. FastAPI, like Django, includes docs changes together with code changes in a single (these days called) pull request; it clearly documents that certain features are deprecated; and its docs often go beyond what is strictly required, by including end-to-end instructions for integrating with various third-party tools and services.
FastAPI's docs raise the bar further still, with more than a dash of humour in many sections, and with a frequent sprinkling of emojis as standard fare. That latter convention I have some reservations about – call me old-fashioned, but you could say that emoji-filled docs is unprofessional and is a distraction. However, they seem to enhance rather than detract from overall quality; and, you know what, they put a non-emoji real-life smile on my face. So, they get my tick of approval.
FastAPI more-or-less sits in the Flask camp of being a "microframework", in that it doesn't include an ORM, a template engine, or various other things that Django has always advertised as being part of its "batteries included" philosophy. But, on the other hand, it's more in the Django camp of being highly opinionated, and of consciously including things with which it wants a hassle-free experience. Most notably, it includes Swagger UI and Redoc out-of-the-box. I personally had quite a painful experience generating Swagger docs in Flask, back in the day; and I've been tremendously pleased with how API doc generation Just Works™ in FastAPI.
Much like with Flask, being a microframework means that FastAPI very much stands on the shoulders of giants. Just as Flask is a thin wrapper on top of Werkzeug, with the latter providing all things WSGI; so too is FastAPI a thin wrapper on top of Starlette, with the latter providing all things ASGI. FastAPI also heavily depends on Pydantic for data schemas / validation, for strongly-typed superpowers, for settings handling, and for all things JSON. I think it's fair to say that Pydantic is FastAPI's secret sauce.
My use of FastAPI so far has been rather unusual, in that I've been building apps that primarily talk to an Oracle database (and, indeed, this is unusual for Python dev more generally). I started out by depending on the (now-deprecated) cx_Oracle library, and I've recently switched to its successor python-oracledb. I was pleased to see that the fine folks at Oracle recently released full async support for python-oracledb, which I'm now taking full advantage of in the context of FastAPI. I wrote a little library called fastapi-oracle which I'm using as a bit of glue code, and I hope it's of use to anyone else out there who needs to marry those two particular bits of tech together.
There has been a not-insignificant amount of chit-chat on the interwebz lately, voicing concern that FastAPI is a one-man show (with its BDFL @tiangolo showing no intention of that changing anytime soon), and that the FastAPI issue and pull request queues receive insufficient TLC. Based on my experience so far, I'm not too concerned about this. It is, generally speaking, not ideal if a project has a bus factor of 1, and if support requests and bug fixes are left to rot.
However, in my opinion, the code and the documentation of FastAPI are both high-quality and highly-consistent, and I appreciate that this is largely thanks to @tiangolo continuing to personally oversee every small change, and that loosening the reins would mean a high risk of that deteriorating. And, speaking of quality, I personally have yet to uncover any bugs either in FastAPI or its core dependencies (which I'm pleasantly surprised by, considering how heavily I've been using it) – it would appear that the items languishing in the queue are lower priority, and it would appear that @tiangolo is on top of critical bugs as they arise.
In summary, I'm enjoying coding with FastAPI, I feel like it's a great fit for building Python web apps in 2024, and it will continue to be my Python framework of choice for the foreseeable future.
April 27, 2024
Trey Hunner
10 years of Python conferences
10 years and 10 days ago I flew home from my very first Python conference.
I left a few days into the PyCon US 2014 sprints and I remember feeling a bit like summer camp was ending. I’d played board games, contributed to an open source project, seen tons of talks, and met a ton of people.
My first Python conference: PyCon US 2014
PyCon 2014 was the first Python conference I attended.
At the start of the conference I only knew a handful of San Diegans. I left having met many more folks. Some of the folks I met I knew from online forums, GitHub repos, or videos I met Kenneth Love, Baptiste Mispelon, Carl Meyer, Eric Holscher in-person, among many others. Most folks I met I had never encountered online, but I was glad to have met in person.
For the most part, I had no idea who anyone was, what they did with Python, or what they might be interested in talking about. I also had no idea what most of the various non-talk activities were. I found out about the Education Summit and hadn’t realized that it required pre-registration. The open spaces are one of my favorite parts of PyCon and I didn’t even they existed until PyCon 2015.
I did stay for a couple days of the sprints and I was grateful for that. Most of the memorable human connections I had were during the sprints. I helped PyVideo upgrade their code base from Python 2 to Python 3 (this was before Will and Sheila stepped down as maintainers). Will guided me through the code base and seemed grateful for the help.
I also got the idea to write front-end JavaScript tests for Django during the sprints and eventually started that process after PyCon thanks to Carl Meyer’s guidance.
Attending regional conferences and DjangoCon
In fall 2014, I attended Django BarCamp at the Eventbrite office. That was my first exposure to the idea of an “unconference”… which I kept in mind when I spotted the open spaces board at PyCon 2015.
Before coming back to Montreal for PyCon 2015, I emailed Harry Percival to ask if he could use a teaching assistant during his tutorial on writing tests. His reply was much more enthusiastic than I expected: “YES YES OH GOD YES THANK YOU THANK YOU THANK YOU TREY”. I was very honored to be able to help Harry, as my testing workflow was heavily inspired by many blog posts he’d written about testing best practices in Django.
I coached at my first Django Girls event in 2015 in Ensenada and then my second at DjangoCon 2015 in Austin. I gave my first lightning talk at DjangoCon 2015, comparing modern JavaScript to Python. It was a lightning talk I had given at the San Diego JavaScript and San Diego Python meetups.
In 2016, I attended PyTennessee in Nashville. I remember attending a dinner of of about a dozen folks who spoke at the conference. I was grateful to get to chat with so many folks whose talks I’d attended.
Presenting talks and tutorials
I presented my first conference tutorial at PyCon 2016 in Portland and my first talk at DjangoCon US 2016 in Philadelphia. I had been presenting lightning talks every few months at my local Python and JavaScript meetups for a few years by then and I had hosted free workshops at my local meetup and paid workshops for training clients.
Having presented locally helped, but presenting on a big stage is always scary.
Volunteering
I volunteered at some of my first few conferences and found that I really enjoyed it. I especially enjoyed running the registration desk, as you’re often the first helpful face that people see coming into the conference.
During PyCon 2016, 2017, and 2018, I co-chaired the open spaces thanks to Anna Ossowski inviting me to help. I had first attended open spaces during PyCon 2015 and I loved them. Talks are great, but so are discussions!
I also ran for the PSF board of directors in 2016 and ended up serving on the board for a few years before stepping down. After my board terms, I volunteered for the PSF Code of Conduct working group for about 6 years. I didn’t even know what the PSF was until PyCon 2015!
A lot of travel… maybe too much
After DjangoCon 2016, I went a bit conference-wild. I attended PyTennessee 2017, PyCaribbean 2017 in Puerto Rico, PyCon US 2017 in Portland, PyCon Australia 2017 in Melbourne, DjangoCon 2017 in Spokane, PyGotham 2017 in NYC, and North Bay Python 2017 in Petaluma.
In 2018 I sponsored PyTennessee and PyOhio and spoke at both. I passed out chocolate chip cookies at PyTennessee as a way to announce the launch of Python Morsels. I also attended PyCon 2018 in Cleveland, DjangoCon 2018 in San Diego, PyGotham 2018, and North Bay Python 2018.
I slowed down a bit in 2019, with just PyCascades (Seattle), PyCon US (Cleveland), PyCon Australia (Sydney), and DjangoCon US (San Diego, which is home for me).
Since the pandemic
Since the start of the pandemic, I’ve attended PyCon US 2022, DjangoCon 2022 in San Diego (in my city for the third time!) and PyCon US 2023. Traveling is more challenging for me than it used to be, but I hope to attend more regional conferences again soon.
Between client work, I’ve been focusing less on conferences and more on blog posts (over here), screencasts, my weekly Python tips emails, and (of course) on Python Morsels.
My journey started locally
I became part of the Python community before I knew I was part of it.
I started using Python professionally in December 2009 and I attended my first San Diego Python meetup in March 2012. I met the organizers, gave some lightning talks, attended Saturday study group sessions (thanks Carol Willing, Alain Domissy, and others for running these), and volunteered to help organize meetups, study groups, and workshops.
By 2014, I had learned from folks online and in-person and I had helped out at my local Python meetup. I had even made a few contributions to some small Django packages I relied on heavily.
I was encouraged to attend PyCon 2014 by others who were attending (thanks Carol, Micah, and Paul among others). The conference was well-worth the occasional feeling of overwhelm.
We’re all just people
The biggest thing I’ve repeatedly learned over the past decade of Python conferences is that we’re all just people.
Carol Willing keynoted PyCon US 2023. But I met Carol as a kind Python user in San Diego who started the first Python study group meetings in Pangea Bakery on Convoy Street.
Jay Miller will be keynoting PyCon US 2024. But I met Jay as an attendee of the Python study group, who was enthusiastic about both learning and teaching others.
My partner, Melanie Arbor, keynoted DjangoCon 2022 along with Jay Miller. When I met Melanie, she was new to Python and was very eager to both learn and help others.
David Lord has made a huge impact on the maintenance of Flask and other Pallets projects. I met David as a Python study group attendee who was an enthusiastic StackOverflow contributor.
I learned a ton from Brandon Rhodes, Ned Batchelder, Russell Keith-Magee, and many others from online videos, forums, and open source projects before I ever met them. But each of them are also just Python-loving people like the rest of us. Russell gives good hugs, Ned is an organizer of his local Python meetup, and Brandon wears the same brand of shoes as me.
We all have people we’ve learned from, we suffer from feelings of inadequacy, we get grumpy sometimes, and we care about the Python language and community in big and small ways.
What’s next for you?
Will you attend a local meetup? Or will you attend an online social event?
If so, consider asking the organize if you can present a 5 minute lightning talk at a future event. As I noted in a DjangoCon 2016 lightning talk, lightning talks are a great way to connect with folks.
Will you attend a Python conference one day? See having a great first PyCon when/if you do.
Remember that we’re all just people though. Some may have a bit more experience (whether at speaking, contributing to open source, or something else), but we’re just people.
Talk Python to Me
#459: I Built A Python SaaS with AI
We all know that tools like ChatGPT have really empowered developers to tackle bigger problems. Are you using TailwindCSS and need a login page? Try asking Chat "What is the HTML for a login page with the login username, password, and button in its own section in the center of the page?" It will literally give you a first pass version of it. But how far can you push this? Fred Tubiermont may have taken it farther than most. He built a functioning SaaS product with paying customers by only using ChatGPT and Python. It's fascinating to hear his story.<br/> <br/> <strong>Episode sponsors</strong><br/> <br/> <a href='https://talkpython.fm/mailtrap'>Mailtrap</a><br> <a href='https://talkpython.fm/training'>Talk Python Courses</a><br/> <br/> <strong>Links from the show</strong><br/> <br/> <div><b>Frederick Tubiermont</b>: <a href="https://www.linkedin.com/in/fredericktubiermont/" target="_blank" rel="noopener">linkedin.com</a><br/> <b>The #1 AI Jingle Generator</b>: <a href="https://www.aijinglemaker.com" target="_blank" rel="noopener">aijinglemaker.com</a><br/> <b>Fred's YouTube Channel</b>: <a href="https://www.youtube.com/@callmefred" target="_blank" rel="noopener">youtube.com</a><br/> <b>AI Coding Club</b>: <a href="https://aicodingclub.com" target="_blank" rel="noopener">aicodingclub.com</a><br/> <b>No Code</b>: <a href="https://www.saashub.com/best-no-code-software" target="_blank" rel="noopener">saashub.com</a><br/> <b>Prompt Engineering 101 - Crash Course & Tips</b>: <a href="https://www.youtube.com/watch?v=aOm75o2Z5-o" target="_blank" rel="noopener">youtube.com</a><br/> <b>gpt-engineer</b>: <a href="https://github.com/gpt-engineer-org/gpt-engineer" target="_blank" rel="noopener">github.com</a><br/> <b>Instant Deployments, Effortless Scale</b>: <a href="https://railway.app" target="_blank" rel="noopener">railway.app</a><br/> <b>Self-hosting with superpowers.</b>: <a href="https://coolify.io" target="_blank" rel="noopener">coolify.io</a><br/> <b>The newsletter platform built for growth.</b>: <a href="https://www.beehiiv.com" target="_blank" rel="noopener">beehiiv.com</a><br/> <b>Watch this episode on YouTube</b>: <a href="https://www.youtube.com/watch?v=lbX3B04sS1s" target="_blank" rel="noopener">youtube.com</a><br/> <b>Episode transcripts</b>: <a href="https://talkpython.fm/episodes/transcript/459/i-built-a-python-saas-with-ai" target="_blank" rel="noopener">talkpython.fm</a><br/> <br/> <b>--- Stay in touch with us ---</b><br/> <b>Subscribe to us on YouTube</b>: <a href="https://talkpython.fm/youtube" target="_blank" rel="noopener">youtube.com</a><br/> <b>Follow Talk Python on Mastodon</b>: <a href="https://fosstodon.org/web/@talkpython" target="_blank" rel="noopener"><i class="fa-brands fa-mastodon"></i>talkpython</a><br/> <b>Follow Michael on Mastodon</b>: <a href="https://fosstodon.org/web/@mkennedy" target="_blank" rel="noopener"><i class="fa-brands fa-mastodon"></i>mkennedy</a><br/></div>
ListenData
How to use variable in a query in pandas
Suppose you want to reference a variable in a query in pandas package in Python. This seems to be a straightforward task but it becomes daunting sometimes. Let's discuss it with examples in the article below.
Let's create a sample dataframe having 3 columns and 4 rows. This dataframe is used for demonstration purpose.
import pandas as pd
df = pd.DataFrame({"col1" : range(1,5),
"col2" : ['A A','B B','A A','B B'],
"col3" : ['A A','A A','B B','B B']
})
A A
in column col2
In order to do reference of a variable in query, you need to use @
.
newdf = df.query("col2 == 'A A'")
myval1 = 'A A'
newdf = df.query("col2 == @myval1")
Instead of filtering value we are referring the column which we want to use for filtering.
myvar1 = 'col2'
newdf2 = df.query("{0} == 'A A'".format(myvar1))
{0} takes a value of variable myvar1."{0} == 'A A'".format(myvar1)
returns"col2 == 'A A'"
Incase you want to pass multiple columns as variables in query. Here we are using columns col2
and col3
.
myvar1 = 'col2'
myvar2 = 'col3'
newdf2 = df.query("{0} == 'A A' & {1} == 'B B'".format(myvar1, myvar2))
"{0} == 'A A' & {1} == 'B B'".format(myvar1, myvar2)
is equivalent to "col2 == 'A A' & col3 == 'B B'"
Let's rename column col2
by including a space in between for illustration purpose.
df.rename(columns={'col2':'col 2'}, inplace = True)
By using backticks ``
you can pass a column which contains space.
myvar1 = '`col 2`'
newdf = df.query("{0} == 'A A'".format(myvar1))
4 Ways to Correct Grammar with Python
This tutorial explains various methods for checking and correcting grammar using Python. Automatic grammar correction helps students, professionals and content creators to make sure their writing follows proper grammar rules.
To read this article in full, please click hereApril 26, 2024
ListenData
How to Scrape Google News with Python
This tutorial explains how to scrape Google News for articles related to the topic of your choice using Python.
We are interested to see the following information for each news article.
- Title : Article Headline
- Source : Original News Source or Blogger Name
- Time : Publication Date/Time
- Author : Article Author
- Link : Article Link
4 Ways to Use ChatGPT API in Python
In this tutorial, we will explain how to use ChatGPT API in Python, along with examples.
Please follow the steps below to access the ChatGPT API.
- Visit the OpenAI Platform and sign up using your Google, Microsoft or Apple account.
- After creating your account, the next step is to generate a secret API key to access the API. The API key looks like this -
sk-xxxxxxxxxxxxxxxxxxxx
- If your phone number has not been associated with any other OpenAI account previously, you may get free credits to test the API. Otherwise you have to add atleast 5 dollars into your account and charges will be based on the usage and the type of model you use. Check out the pricing details in the OpenAI website.
- Now you can call the API using the code below.
Real Python
Quiz: What Is the __pycache__ Folder in Python?
As your Python project grows, you typically organize your code in modules and packages for easier maintenance and reusability. When you do that, you’ll likely notice the sudden emergence of a __pycache__
folder alongside your original files, popping up in various locations unexpectedly.
[ Improve Your Python With đ Python Tricks đ â Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]
The Real Python Podcast â Episode #202: Pydantic Data Validation & Python Web Security Practices
How do you verify and validate the data coming into your Python web application? What tools and security best practices should you consider as a developer? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder's Weekly articles and projects.
[ Improve Your Python With đ Python Tricks đ â Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]
April 25, 2024
Data School
How to prevent data leakage in pandas & scikit-learn â
Let&aposs pretend you&aposre working on a supervised Machine Learning problem using Python&aposs scikit-learn library. Your training data is in a pandas DataFrame, and you discover missing values in a column that you were planning to use as a feature.
After considering your options, you decide to impute the missing values, which means that you&aposre going to fill in the missing values with reasonable values.
How should you perform the imputation?
- Option 1 is to fill in the missing values in pandas, and then pass the transformed data to scikit-learn.
- Option 2 is to pass the original data to scikit-learn, and then perform all data transformations (including missing value imputation) within scikit-learn.
Option 1 will cause data leakage, whereas option 2 will prevent data leakage.
Here are questions you might be asking:
- What is data leakage?
- Why is data leakage problematic?
- Why would data leakage result from missing value imputation in pandas?
- How can I prevent data leakage when using pandas and scikit-learn?
Answers below! 👇
What is data leakage?
Data leakage occurs when you inadvertently include knowledge from testing data when training a Machine Learning model.
Why is data leakage problematic?
Data leakage is problematic because it will cause your model evaluation scores to be less reliable. This may lead you to make bad decisions when tuning hyperparameters, and it will lead you to overestimate how well your model will perform on new data.
It&aposs hard to know whether data leakage will skew your evaluation scores by a negligible amount or a huge amount, so it&aposs best to just avoid data leakage entirely.
Why would data leakage result from missing value imputation in pandas?
Your model evaluation procedure (such as cross-validation) is supposed to simulate the future, so that you can accurately estimate right now how well your model will perform on new data.
But if you impute missing values on your whole dataset in pandas and then pass your dataset to scikit-learn, your model evaluation procedure will no longer be an accurate simulation of reality. That&aposs because the imputation values will be based on your entire dataset (meaning both the training portion and the testing portion), whereas the imputation values should just be based on the training portion.
In other words, imputation based on the entire dataset is like peeking into the future and then using what you learned from the future during model training, which is definitely not allowed.
How can we avoid this in pandas?
You might think that one way around this problem would be to split your dataset into training and testing sets and then impute missing values using pandas. (Specifically, you would need to learn the imputation value from the training set and then use it to fill in both the training and testing sets.)
That would work if you&aposre only ever planning to use train/test split for model evaluation, but it would not work if you&aposre planning to use cross-validation. That&aposs because during 5-fold cross-validation (for example), the rows contained in the training set will change 5 times, and thus it&aposs quite impractical to avoid data leakage if you use pandas for imputation while using cross-validation!
How else can data leakage arise?
So far, I&aposve only mentioned data leakage in the context of missing value imputation. But there are other transformations that if done in pandas on the full dataset will also cause data leakage.
For example, feature scaling in pandas would lead to data leakage, and even one-hot encoding (or "dummy encoding") in pandas would lead to data leakage unless there&aposs a known, fixed set of categories.
More generally, any transformation which incorporates information about other rows when transforming a row will lead to data leakage if done in pandas.
How does scikit-learn prevent data leakage?
Now that you&aposve learned how data transformations in pandas can cause data leakage, I&aposll briefly mention three ways in which scikit-learn prevents data leakage:
- First, scikit-learn transformers have separate
fit
andtransform
steps, which allow you to base your data transformations on the training set only, and then apply those transformations to both the training set and the testing set. - Second, the
fit
andpredict
methods of a Pipeline encapsulate all calls tofit_transform
andtransform
so that they&aposre called at the appropriate times. - Third,
cross_val_score
splits the data prior to performing data transformations, which ensures that the transformers only learn from the temporary training sets that are created during cross-validation.
Conclusion
When working on a Machine Learning problem in Python, I recommend performing all of your data transformations in scikit-learn, rather than performing some of them in pandas and then passing the transformed data to scikit-learn.
Besides helping you to prevent data leakage, this enables you to tune the transformer and model hyperparameters simultaneously, which can lead to a better performing model!
One final note...
This post is an excerpt from my upcoming video course, Master Machine Learning with scikit-learn.
Join the waitlist below to get free lessons from the course and a special launch discount 👇
Programiz
Getting Started with Python
In this tutorial, you will learn to write your first Python program.
Django Weblog
Livestream: Django Trends for 2024
Today at 3pm UTC â Discover the latest trends in the Django ecosystem, based on insights from 4,000 developers who participated in the Django Developers Survey. Join the livestream with Sarah Abderemane, a Django Software Foundation Board member, and Sarah Boyce, a Django Fellow, to reflect on insights from the Django community.
April 24, 2024
Sumana Harihareswara - Cogito, Ergo Sumana
Model UX Research & Design Docs for Command-Line Open Source
Model UX Research & Design Docs for Command-Line Open Source
Real Python
What's Lazy Evaluation in Python?
Being lazy is not always a bad thing. Every line of code you write has at least one expression that Python needs to evaluate. Python lazy evaluation is when Python takes the lazy option and delays working out the value returned by an expression until that value is needed.
An expression in Python is a unit of code that evaluates to a value. Examples of expressions include object names, function calls, expressions with arithmetic operators, literals that create built-in object types such as lists, and more. However, not all statements are expressions. For example, if
statements and for
loop statements donât return a value.
Python needs to evaluate every expression it encounters to use its value. In this tutorial, youâll learn about the different ways Python evaluates these expressions. Youâll understand why some expressions are evaluated immediately, while others are evaluated later in the programâs execution. So, whatâs lazy evaluation in Python?
Get Your Code: Click here to download the free sample code that shows you how to use lazy evaluation in Python.
Take the Quiz: Test your knowledge with our interactive âWhat's Lazy Evaluation in Python?â quiz. Youâll receive a score upon completion to help you track your learning progress:
Interactive Quiz
What's Lazy Evaluation in Python?In this quiz, you'll test your understanding of the differences between lazy and eager evaluation in Python. By working through this quiz, you'll revisit how Python optimizes memory use and computational overhead by deciding when to compute values.
In Short: Python Lazy Evaluation Generates Objects Only When Needed
An expression evaluates to a value. However, you can separate the type of evaluation of expressions into two types:
- Eager evaluation
- Lazy evaluation
Eager evaluation refers to those cases when Python evaluates an expression as soon as it encounters it. Here are some examples of expressions that are evaluated eagerly:
1>>> 5 + 10
215
3
4>>> import random
5>>> random.randint(1, 10)
64
7
8>>> [2, 4, 6, 8, 10]
9[2, 4, 6, 8, 10]
10>>> numbers = [2, 4, 6, 8, 10]
11>>> numbers
12[2, 4, 6, 8, 10]
Interactive environments, such as the standard Python REPL used in this example, display the value of an expression when the line only contains the expression. This code section shows a few examples of statements and expressions:
- Lines 1 and 2: The first example includes the addition operator
+
, which Python evaluates as soon as it encounters it. The REPL shows the value15
. - Lines 4 to 6: The second example includes two lines:
- The import statement includes the keyword
import
followed by the name of a module. The module namerandom
is evaluated eagerly. - The function call
random.randint()
is evaluated eagerly, and its value is returned immediately. All standard functions are evaluated eagerly. Youâll learn about generator functions later, which behave differently.
- The import statement includes the keyword
- Lines 8 to 12: The final example has three lines of code:
- The literal to create a list is an expression thatâs evaluated eagerly. This expression contains several integer literals, which are themselves expressions evaluated immediately.
- The assignment statement assigns the object created by the list literal to the name
numbers
. This statement is not an expression and doesnât return a value. However, it includes the list literal on the right-hand side, which is an expression thatâs evaluated eagerly. - The final line contains the name
numbers
, which is eagerly evaluated to return the list object.
The list you create in the final example is created in full when you define it. Python needs to allocate memory for the list and all its elements. This memory wonât be freed as long as this list exists in your program. The memory allocation in this example is small and wonât impact the program. However, larger objects require more memory, which can cause performance issues.
Lazy evaluation refers to cases when Python doesnât work out the values of an expression immediately. Instead, the values are returned at the point when theyâre required in the program. Lazy evaluation can also be referred to as call-by-need.
This delay of when the program evaluates an expression delays the use of resources to create the value, which can improve the performance of a program by spreading the time-consuming process across a longer time period. It also prevents values that will not be used in the program from being generated. This can occur when the program terminates or moves to another part of its execution before all the generated values are used.
When large datasets are created using lazily-evaluated expressions, the program doesnât need to use memory to store the data structureâs contents. The values are only generated when theyâre needed.
An example of lazy evaluation occurs within the for
loop when you iterate using range()
:
for index in range(1, 1_000_001):
print(f"This is iteration {index}")
The built-in range()
is the constructor for Pythonâs range
object. The range
object does not store all of the one million integers it represents. Instead, the for
loop creates a range_iterator
from the range
object, which generates the next number in the sequence when itâs needed. Therefore, the program never needs to have all the values stored in memory at the same time.
Lazy evaluation also allows you to create infinite data structures, such as a live stream of audio or video data that continuously updates with new information, since the program doesnât need to store all the values in memory at the same time. Infinite data structures are not possible with eager evaluation since they canât be stored in memory.
There are disadvantages to deferred evaluation. Any errors raised by an expression are also deferred to a later point in the program. This delay can make debugging harder.
The lazy evaluation of the integers represented by range()
in a for
loop is one example of lazy evaluation. Youâll learn about more examples in the following section of this tutorial.
What Are Examples of Lazy Evaluation in Python?
In the previous section, you learned about using range()
in a for
loop, which leads to lazy evaluation of the integers represented by the range
object. There are other expressions in Python that lead to lazy evaluation. In this section, youâll explore the main ones.
Other Built-In Data Types
Read the full article at https://realpython.com/python-lazy-evaluation/ »
[ Improve Your Python With đ Python Tricks đ â Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]
Talk Python to Me
#458: Serverless Python in 2024
What is the state of serverless computing and Python in 2024? What are some of the new tools and best practices? We are lucky to have Tony Sherman who has a lot of practical experience with serverless programming on the show.<br/> <br/> <strong>Episode sponsors</strong><br/> <br/> <a href='https://talkpython.fm/sentry'>Sentry Error Monitoring, Code TALKPYTHON</a><br> <a href='https://talkpython.fm/mailtrap'>Mailtrap</a><br> <a href='https://talkpython.fm/training'>Talk Python Courses</a><br/> <br/> <strong>Links from the show</strong><br/> <br/> <div><b>Tony Sherman on Twitter</b>: <a href="https://twitter.com/tsh3rman" target="_blank" rel="noopener">twitter.com</a><br/> <b>Tony Sherman</b>: <a href="https://www.linkedin.com/in/tony--sherman/" target="_blank" rel="noopener">linkedin.com</a><br/> <b>PyCon serverless talk</b>: <a href="https://www.youtube.com/watch/2SZ6Wks5iK4" target="_blank" rel="noopener">youtube.com</a><br/> <b>AWS re:Invent talk</b>: <a href="https://www.youtube.com/watch?v=52W3Qyg242Y" target="_blank" rel="noopener">youtube.com</a><br/> <b>Powertools for AWS Lambda</b>: <a href="https://docs.powertools.aws.dev/lambda/python/latest/" target="_blank" rel="noopener">docs.powertools.aws.dev</a><br/> <b>Pantsbuild: The ergonomic build system</b>: <a href="https://www.pantsbuild.org/" target="_blank" rel="noopener">pantsbuild.org</a><br/> <b>aws-lambda-power-tuning</b>: <a href="https://github.com/alexcasalboni/aws-lambda-power-tuning" target="_blank" rel="noopener">github.com</a><br/> <b>import-profiler</b>: <a href="https://github.com/cournape/import-profiler" target="_blank" rel="noopener">github.com</a><br/> <b>AWS Fargate</b>: <a href="https://aws.amazon.com/fargate/" target="_blank" rel="noopener">aws.amazon.com</a><br/> <b>Run functions on demand. Scale automatically.</b>: <a href="https://www.digitalocean.com/products/functions" target="_blank" rel="noopener">digitalocean.com</a><br/> <b>Vercel</b>: <a href="https://vercel.com/docs/functions/serverless-functions/runtimes/python" target="_blank" rel="noopener">vercel.com</a><br/> <b>Deft</b>: <a href="https://deft.com" target="_blank" rel="noopener">deft.com</a><br/> <b>37 Signals We stand to save $7m over five years from our cloud exit</b>: <a href="https://world.hey.com/dhh/we-stand-to-save-7m-over-five-years-from-our-cloud-exit-53996caa" target="_blank" rel="noopener">world.hey.com</a><br/> <b>The Global Content Delivery Platform That Truly Hops</b>: <a href="https://bunny.net" target="_blank" rel="noopener">bunny.net</a><br/> <b>Watch this episode on YouTube</b>: <a href="https://www.youtube.com/watch?v=A5bbUq-ZJh0" target="_blank" rel="noopener">youtube.com</a><br/> <b>Episode transcripts</b>: <a href="https://talkpython.fm/episodes/transcript/458/serverless-python-in-2024" target="_blank" rel="noopener">talkpython.fm</a><br/> <br/> <b>--- Stay in touch with us ---</b><br/> <b>Subscribe to us on YouTube</b>: <a href="https://talkpython.fm/youtube" target="_blank" rel="noopener">youtube.com</a><br/> <b>Follow Talk Python on Mastodon</b>: <a href="https://fosstodon.org/web/@talkpython" target="_blank" rel="noopener"><i class="fa-brands fa-mastodon"></i>talkpython</a><br/> <b>Follow Michael on Mastodon</b>: <a href="https://fosstodon.org/web/@mkennedy" target="_blank" rel="noopener"><i class="fa-brands fa-mastodon"></i>mkennedy</a><br/></div>
Test and Code
219: Building Django Apps & SaaS Pegasus - Cory Zue
I'm starting a SaaS project using Django, and there are tons of decisions right out of the gate.
To help me navigate these decisions, I've brought on Cory Zue. Â
Cory is the creator of SaaS Pegasus, and has tons of experience with Django.
Some of the topics discussed:
- Building Django applications
- SaaS Pegasus
- placecard.me
- What boilerplate projects are
- Django cookiecutter
- Cookiecutter
- Which database to use, probably PostgreSQL
- Authentication choises, probably Allauth
- Docker, Docker for development, Docker for deployment
- Deployment targets / hosting services. Render, Heroku, Fly.io, for PaaS options.
- Front end frameworks. Bootstrap, Tailwind, DaisyUI, TailwindUI
- HTMX vs React vs straight Django templates
- Rockets
- Font Awesome
- and of course, SaaS Pegasus
Sponsored by Mailtrap.io
- An Email Delivery Platform that developers love.Â
- An email-sending solution with industry-best analytics, SMTP, and email API, SDKs for major programming languages, and 24/7 human support.Â
- Try for Free at MAILTRAP.IO
Sponsored by PyCharm Pro
- Use code PYTEST for 20% off PyCharm Professional at jetbrains.com/pycharm
- Now with Full Line Code Completion
- See how easy it is to run pytest from PyCharm at pythontest.com/pycharm
The Complete pytest Course
- For the fastest way to learn pytest, go to courses.pythontest.com
- Whether your new to testing or pytest, or just want to maximize your efficiency and effectiveness when testing.
Seth Michael Larson
Open Source Summit North America 2024
Open Source Summit North America 2024
This critical role would not be possible without funding from the Alpha-Omega project. Massive thank-you to Alpha-Omega for investing in the security of the Python ecosystem!
Last week I attended SOSS Community Day and OSS Summit. It was great to catch up with friends and to meet new people for the first time at a cross-ecosystem open source event.
I gave a talk "Embrace the Differences: Securing software ecosystems where they are" which funnily enough had a complementary talk about the ways software repositories can collaborate for security.
My talk focused on how security standards and tools typically want to operate across software ecosystems and differences in standards, tools, maintainers, and user expectations between ecosystems can make that difficult.
You can download my slides and the recording will be available eventually on YouTube.
OpenSSF Tabletop Session
I also participated in the first OpenSSF Tabletop Session organized and hosted by Dana Wang. I played the role of "open source maintainer" and represented how an exploited zero-day vulnerability would appear from the perspective of an open source project.
I emphasized the realities of vulnerability disclosure to open source projects like under-resourcing, most maintainers being volunteers, and stress caused during times of crisis.
So many people!
I also met up with many folks doing open source security, maintenance, and funding:- Met with many folks from the Alpha-Omega cohort. I'm looking forward to having more cross-functional discussions about new approaches to securing open source.
- Met with Michael Winser from Alpha-Omega to work on our PyCon US 2024 talk State of Supply Chain Security for Python.
- Met with my friend William Woodruff from Trail of Bits and discussed the system TLS proposal and build provenance for Homebrew (and what could be learned for Python).
- Met with Samuel Giddins and Martin Emde from the Ruby ecosystem to discuss shared challenges for introducing security into an ecosystem.
- Met Lauren Hanford from Tidelift to discuss supporting and funding maintainers.
- Met Mirko from Sovereign Tech Fund and discuss their program for hiring open source maintainers.
- Attended the talk by Kara Sowles from GitHub on the state of open source funding and learned about "downturn-resilient" funding.
- Many folks who asked me about security initiatives happening in the Python ecosystem.
Other items
- Participating in the pre-PEP discussion for reviving PEP 543 (system TLS).
- Created a proposal for allowing any release manager to create a CPython release.
- Created a pull request for uploading Windows SBOMs to python.org/downloads.
- Merging and backporting the upgrade to libexpat 2.6.2
- Chose which proposal(s) I would be willing to mentor for Google Summer of Code 2024 (thanks to the folks who submitted!)
- Triaged reports and fixes for the PSRT.
- I wasn't involved, but PyPI has added Trusted Publisher support for ActiveState, GitLab, and Google Cloud Build.
Note that I've been summoned for jury duty starting next week, so expect fewer updates over the next two weeks depending on how that goes.
That's all for this week! đ If you're interested in more you can read last week's report.
Thanks for reading! ⥠Did you find this article helpful and want more content like it? Get notified of new posts by subscribing to the RSS feed or the email newsletter.
This work is licensed under CC BY-SA 4.0
April 23, 2024
PyCoderâs Weekly
Issue #626 (April 23, 2024)
#626 â APRIL 23, 2024
View in Browser »
Asyncio Handle Control-C (SIGINT)
When the user presses CTRL-C on the keyboard, the OS raises an interrupt signal to your program. When writing concurrent code this can get complicated as the signal goes to the process. This article shows you how to handle capturing CTRL-C elegantly when using asyncio
.
JASON BROWNLEE
Using raise
for Effective Exceptions
In this video course, you’ll learn how to raise exceptions in Python, which will improve your ability to efficiently handle errors and exceptional situations in your code. This way, you’ll write more reliable, robust, and maintainable code.
REAL PYTHON course
Securing Python and Open Source Ecosystems
Join this fireside chat featuring Dustin Ingram, Fellow at the Python Software Foundation (PSF), as we discuss trust and security for PyPI and other repositories in light of recent attacks, and initiatives such as Trusted Publishing - Tune in this Thursday! â
ACTIVESTATE sponsor
Ruff Gets a Big Speed-Up
Ruff has changed from a generated parser to a hand-written recursive descent parser in the latest release. This has resulted in >2x speedup in its linting performance. This article covers what has changed and why they did it.
DHRUV MANILAWALA
Articles & Tutorials
OpenStreetMaps, Overpass API and Python
OpenStreetMaps (OSM) is an an open source mapping project that allows people to browse the world map and to plan routes. Not only does it have the expected web interface, but it also has an API known as Overpass. This article shows you two ways to use Python to query Overpass.
JUDITH VOCKENROTH
Python Gotcha: strip
Can Remove More Than Expected
The Python strip
, lstrip
, and rstrip
functions can have unexpected behavior: they strip a list of characters, not strings. Even though this is documented, it can lead to unexpected results. This post explains what happens and shows you two functions to use instead.
ANDREW WEGNER
Decoupling Systems to Get Closer to the Data
What are the benefits of using a decoupled data processing system? How do you write reusable queries for a variety of backend data platforms? This week on the show, Phillip Cloud, the lead maintainer of Ibis, will discuss this portable Python dataframe library.
REAL PYTHON podcast
Announcing py2wasm
: A Python to Wasm Compiler
Wasmer, a company that builds Wasm tools, has announced py2wasm
which converts your Python programs to WebAssembly, running at 3x faster speeds than direct Wasm. This post introduces you to the tool and shows how they took advantage of the Nuitka library.
SYRUS AKBARY
How to Format Floats Within F-Strings in Python
In this tutorial, you’ll learn how to use Python format specifiers within an f-string to allow you to neatly format a float to your required precision. You’ll also learn how to extract digits from existing strings and format them as well.
REAL PYTHON
Memory Management in mpmetrics
The mpmetrics
library contains tools for determining runtime metrics on your code. To do this it requires some esoteric memory management techniques normally not undergone in Python. This post describe what they’ve done and why.
TRENDS BLOG
The Time Complexities Python Data Structures in Python
Big O notation describes the relationship between an algorithm, how much data it is using, and the time it takes to run. This article covers the time complexities of a variety of Python data structures.
TREY HUNNER
Django Project on NGINX Unit
Unit is a web server developed by the NGINX folks with pluggable support for Python using WSGI and ASGI. Aidas tried it out and this post talks about how he got some Django code working on this server.
AIDAS BENDORAITIS
I Asked 100 Devs Why They Aren’t Shipping Faster?
Daksh asked 100 developers why they aren’t shipping faster and this blog post shares what he learned. Problems include dependency bugs, overly complicated code bases, waiting on requirements, and more.
DAKSH GUPTA
Shape Typing in Python
This quick blog post shows you how to use Python type checking to ensure the dimensions of matrices being multiplied together. Typing is no longer just “is it an integer”.
JAMES FISHER
Software Needs to Be More Expensive
Open source is free, and although that is a good thing, it also means companies get to take without giving back. This opinion piece talks about how that should change.
GLYPH LEFKOWITZ
Projects & Code
escaping: Suppress Exceptions With Callbacks and Logs
GITHUB.COM/POMPONCHIK âą Shared by Evgeniy Blinov
Events
Weekly Real Python Office Hours Q&A (Virtual)
April 24, 2024
REALPYTHON.COM
SPb Python Drinkup
April 25, 2024
MEETUP.COM
Django Girls Ekpoma Workshop
April 26 to April 28, 2024
DJANGOGIRLS.ORG
Open Source With Python
April 27, 2024
MEETUP.COM
PythOnRio Meetup
April 27, 2024
PYTHON.ORG.BR
Launching Python Niger
April 28 to April 29, 2024
FB.ME
Happy Pythoning!
This was PyCoder’s Weekly Issue #626.
View in Browser »
[ Subscribe to đ PyCoder’s Weekly đ â Get the best Python news, articles, and tutorials delivered to your inbox once a week >> Click here to learn more ]