โEven if you don't use them directly, dataclasses are a good measuring stick for your class-based code.โ
Read more ๐ https://pym.dev/friendly-classes/
#Python & #Django educator & team trainer
I help folks sharpen their Python skills with https://PythonMorsels.com๐๐ช
Also: ostrovegan, sentientist, YIMBY, and I think economics is highly underrated. I don't post about any of those topics very often.
he/him
| ๐ My Weekly Newsletter | https://pym.dev/newsletter |
| ๐ Python Exercises | https://www.pythonmorsels.com |
| ๐บ YouTube | https://www.youtube.com/@PythonMorsels |
| ๐ธ Personal Blog | https://treyhunner.com |
โEven if you don't use them directly, dataclasses are a good measuring stick for your class-based code.โ
Read more ๐ https://pym.dev/friendly-classes/
But why are they named this way?
Wouldn't it be simpler if re.fullmatch() was called re.match() or re.โsearch() was called re.match() and the current behavior of re.match() didn't exist at all?
I think so. But it's too late for that.
This is all confusing due an accident of history.
re.fullmatch() didn't used to exist but re.match() did. By the time they invented re.fullmatch(), the name "match" was already taken.
Personally, I usually just stick with re.โsearch().
๐งต (3/3)
To find a match WITHIN a string, you can use re.โsearch().
To match an entire string against a regex, you can use re.fullmatch().
Using re.fullmatch() is the same as using re.โsearch() with ^ and $ used to anchor to the beginning and end of the string.
In other words, these are equivalent:
match = re.โsearch(r"^\w+$", string)
match = re.fullmatch(r"\w+", string)
re.match() is a weird middle ground between re.โsearch() and re.fullmatch().
๐งต (2/3)
Python Tip #95 (of 365):
Don't use re.match(): it's confusing.
I'm not sure I've ever seen re.match() used when it wasn't being used by mistake.
If you think you want re.match(), you probably want either re.โsearch() or re.fullmatch() instead.
When matching a regex against a string, we're usually either trying to:
1. Find a regular expression within a string
2. Match a regular expression against a whole string
re.match() does neither of those!
๐งต (1/3)
I love the fact that we're at the "Where are we gonna have the game nights?" part of the #PyConUS planning!
(This is not something handled by the organizers of @pycon but by some of the attendees. With that, the conference chair is contributing to the conversation and will, hopefully, be playing with us.)
RE: https://mastodon.social/@coredispatch/116350032773821393
Okay friends, new side quest! I've started a Python core development newsletter!
If you've ever wanted a regular summary straight to your inbox about all the cool things happening in CPython (and adjacent areas), this is it! Like and subscribe!
First edition, room to grow! ๐ณ
I'm pretty sure Mastodon lists are private and none of you can tell you're on my list, but there's now 45 of you on there.
If you're coming and want to say hey, please do favorites/reply!
Looking forward to seeing you at PyCon.
โPython's if statements don't use parentheses.โ
Read more ๐ https://pym.dev/unnecessary-parentheses/