Get a daily drop of Python knowledge 🐍💧 -> https://mathspp.com/drops
Pydon'ts – free Python book 👉 https://mathspp.com/books/pydonts
When I do, I create it by inheriting from `list`.
This gives me almost everything I want for free!
When I do, I create it by inheriting from `list`.
This gives me almost everything I want for free!
A moving average function.
Manually keeping track of all the values being considered for the window is a pain!
Unless you use `collections.deque`.
Its param `maxlen` makes the window automatically evict the values you don't need.
It was supposed to be a reference article...
And I forgot to talk about docstrings! 🤦
What's worse is that no one event pointed that out to me!
I've fixed it now: mathspp.com/blog/pydont...
It was supposed to be a reference article...
And I forgot to talk about docstrings! 🤦
What's worse is that no one event pointed that out to me!
I've fixed it now: mathspp.com/blog/pydont...
A moving average function.
Manually keeping track of all the values being considered for the window is a pain!
Unless you use `collections.deque`.
Its param `maxlen` makes the window automatically evict the values you don't need.
A moving average function.
Manually keeping track of all the values being considered for the window is a pain!
Unless you use `collections.deque`.
Its param `maxlen` makes the window automatically evict the values you don't need.
I mean, after 200 ⭐️⭐️⭐️⭐️⭐️ reviews, this anonymous user could think for a second and realise that the issue wasn't mine/the book's...
🤡
I mean, after 200 ⭐️⭐️⭐️⭐️⭐️ reviews, this anonymous user could think for a second and realise that the issue wasn't mine/the book's...
🤡
I have a folder in a repo with cloudflare workers:
workers/
workerA/**
workerB/**
I want to deploy workers that get changed but not the others!
That's when dorny/path-filters comes in handy! ✨
I have a folder in a repo with cloudflare workers:
workers/
workerA/**
workerB/**
I want to deploy workers that get changed but not the others!
That's when dorny/path-filters comes in handy! ✨
The keyword `assert` takes an expression to its right.
If the expression evaluates to `True`, or Truthy, everything is fine.
But if it doesn’t, you get an `AssertionError`.
That's a pretty unhelpful/generic error...
Here's the fix:
The keyword `assert` takes an expression to its right.
If the expression evaluates to `True`, or Truthy, everything is fine.
But if it doesn’t, you get an `AssertionError`.
That's a pretty unhelpful/generic error...
Here's the fix:
How many string methods that change the case of a string can you name?
I'll give you a hint:
I thought there were only 5 but I was wrong.
How many string methods that change the case of a string can you name?
I'll give you a hint:
I thought there were only 5 but I was wrong.
This is the value of an object when used in a Boolean context.
For example, when used in the condition of an `if` statement.
Most objects are Truthy, with a few exceptions.
For most types, the “nothing” or “empty” value is Falsy.
This is the value of an object when used in a Boolean context.
For example, when used in the condition of an `if` statement.
Most objects are Truthy, with a few exceptions.
For most types, the “nothing” or “empty” value is Falsy.
Everyone can play.
But not everyone plays beautifully…
It requires practice and calculated moves.
Moves that look like arbitrary choices…
But if you know, you’ll see how each decision builds towards a readable codebase.
Everyone can play.
But not everyone plays beautifully…
It requires practice and calculated moves.
Moves that look like arbitrary choices…
But if you know, you’ll see how each decision builds towards a readable codebase.
This module offers a neat way to access the 5 compression modules we have in Python:
👉 bz2
👉 gzip
👉 lzma
👉 zlib
👉 zstd
The first four were already available as standalone modules...
This module offers a neat way to access the 5 compression modules we have in Python:
👉 bz2
👉 gzip
👉 lzma
👉 zlib
👉 zstd
The first four were already available as standalone modules...
The function `oxford_comma`, shown below, demonstrates this technique.
What's the point of the smaller fragments?
The function `oxford_comma`, shown below, demonstrates this technique.
What's the point of the smaller fragments?
Names that start with a leading underscore are “private”.
This means the outside world has no business using them.
E.g., attributes and methods starting with `_` in a class mean they're for that class only.
Names that start with a leading underscore are “private”.
This means the outside world has no business using them.
E.g., attributes and methods starting with `_` in a class mean they're for that class only.
I now have a `tools` subdomain where I host small HTML+JS tools built with LLMs that help me with whatever random things I need.
E.g., I have one that pre-fills my testimonial form and generates a URL I can share easily!
I now have a `tools` subdomain where I host small HTML+JS tools built with LLMs that help me with whatever random things I need.
E.g., I have one that pre-fills my testimonial form and generates a URL I can share easily!
Here's a mnemonic to help you:
👉 `strptime` has a “P” for “Parse date/time”, so string -> date
👉 `strftime` has an “F” for “Format date/time”, so date -> string
Here's a mnemonic to help you:
👉 `strptime` has a “P” for “Parse date/time”, so string -> date
👉 `strftime` has an “F” for “Format date/time”, so date -> string
You can read the rest of this Python joke here 👉 mathspp.com/blog/a-gene...
You can read the rest of this Python joke here 👉 mathspp.com/blog/a-gene...
The returned list with the splits (and possibly the remainder of the string) has a maximum length of `maxsplit + 1`.
The returned list with the splits (and possibly the remainder of the string) has a maximum length of `maxsplit + 1`.
We then uploaded them to (Test) PyPI and we got people to install each other's apps and run them on their own computers.
It was clearly a moment of *fun* for folks involved. 🤩
We then uploaded them to (Test) PyPI and we got people to install each other's apps and run them on their own computers.
It was clearly a moment of *fun* for folks involved. 🤩
The grounded, fundamental approach to OOP resonated well with the participants.
Even those who already knew OOP said they learned a lot by starting with the fundamentals!
What a surprise! (Not...)
The grounded, fundamental approach to OOP resonated well with the participants.
Even those who already knew OOP said they learned a lot by starting with the fundamentals!
What a surprise! (Not...)
Very informative git history.
Very informative git history.
Today I'm teaching OOP from the ground up.
But like, REALLY from the ground up.
Not just “you write class Something then __init__ and `self` is the first argument because reasons”.
Might turn this into a chapter for my book “Pydon'ts”, actually...
Being this excited about my job feels illegal 🤣
Today I'm teaching OOP from the ground up.
But like, REALLY from the ground up.
Not just “you write class Something then __init__ and `self` is the first argument because reasons”.
Might turn this into a chapter for my book “Pydon'ts”, actually...
Become a PSF member if you can!
🧵
Become a PSF member if you can!
Being this excited about my job feels illegal 🤣
Being this excited about my job feels illegal 🤣
But at least I'll sleep well tonight, knowing all “See also” call outs are correctly formatted.
But at least I'll sleep well tonight, knowing all “See also” call outs are correctly formatted.