The video owner has disabled playback on external websites.
This video is no longer available on YouTube.
This video cannot be played right now.
Watch on YouTube
KI-gestützte Lerntools freischalten
Registriere dich, um leistungsstarke Tools zu nutzen, die dir helfen, schneller aus jedem Video zu lernen.
10 Python Features You’re Not Using (But Really Should)
Untertitel (488 Segmente)
Here's a CSV file with millions of sales
records. And here I have a function that
reads the file and computes the total
sales amount. Now, when I run this, you
see that every time I read this file, if
I need it in my code somewhere, it's
going to take time. I mean, it's not
that bad. This file actually reads like
10 million records. So, I'm kind of
surprised it works this fast. But every
time you do it, you actually have to
wait for the dis IO. This is what
happens when I add caching. As you can
see, the second read happens instantly.
And what's really cool is that this is
really easy to add in Python. In today's
video, I'll walk through 10 features
exactly like this. Really powerful and
really easy to add in Python. Now, if
you want to learn more about how to
design a piece of software from scratch,
I have a free guide for you. You can get
this at iron.codes/design
guide. contains seven steps I take when
I design new software and hopefully it
helps you avoid some of the mistakes
that I made in the past.
Guide the link is in the video
description. There's lots of features in
Python that help you reduce code size,
improve clarity, eliminate entire
classes of bugs, and speed up expensive
operations. And unfortunately, most
developers don't know they exist or
don't know when to apply them. And
because they're part of the standard
library, you actually don't need extra
dependencies of frameworks. Python is
really a batteries included language.
Now the first thing I already kind of
showed you is caching. So in the before
version of the code, we simply had this
total from file function. There's
nothing special here. Just uses pandas
to read a CSV file. But if you want to
cache this function, that's actually
really easy to do. So in this case you
simply import from funk tools the cache
decorator and then you just write cache
on top of the total from file function.
If I now run the code then you see that
this is what happens. So the second read
happens instantly. You also see that it
doesn't print reading the file anymore
because this is actually cached. So it
doesn't execute the function twice. So
this is really perfect for expensive
file parsing, large configuration
loading, uh calculations that are
expensive rendering templates or
anything deterministic. You eliminate
duplicated work and it's going to make
your system much more responsive. It's
great fit for uh CLI tools, ETL
processes, any repeated batch
operations. The second feature that I
use a lot is protocols. So if you take a
look at this piece of the script. So
what this does is that it takes a sale
object that's actually a very simple
class that just has an amount and a
currency and a converted value and then
it uses a rate fetcher to convert that
sale amount into a different currency.
Now the code contains these types of uh
type annotations which is fine. Actually
the Python interpreter ignores these at
runtime. So they're mainly there for you
as a developer to better understand the
code. The issue here is that the value
that's injected here is of type static
rate fetcher and that directly ties this
function to this particular class. So if
you wanted to replace this with some
other rate fetching method maybe you
want to take it from a database or you
want to use an external API. This is uh
annoying because then uh the type
doesn't match. You can't simply create
another class that has exactly this
structure and then put it in here. Well,
you can actually your Python code will
run, but you run into all sorts of uh
type issues while you're working on the
code. So, that's not so nice. What's
nice about protocols is that it allows
you to specify a sort of contract of
what an object is supposed to be like
Vollständige Untertitel im Videoplayer verfügbar
Mit Übungen trainieren
Erstelle Vokabel-, Grammatik- und Verständnisübungen aus diesem Video
Kommentare (0)
Zum Kommentieren AnmeldenRegistriere dich, um alle Features freizuschalten
Verfolge deinen Fortschritt, speichere Vokabeln und übe mit Übungen
Interaktiver Modus
Quiz
Richtige Antwort:
Ähnliche Videos
Connect Model Context Protocol (MCP) servers to Android Studio to improve AI agent capabilities
Don't Drink The Ancient Forbidden Mineral Water
Orangutan Communication is Eerily Similar to Ours
REVERSE ENGINEERING: LASER PRINTER TONER CHIP
Two-Minute Case Study - Artificial Intelligence: Sephora's Newest Beauty Advisor
Late Night with Seth Meyers
Quiz
Richtige Antwort:
Quizfragen erscheinen beim Anschauen des Videos
Merkhilfe
Aus diesem Video
Kostenlos Sprachen lernen