this post was submitted on 18 Nov 2024
18 points (100.0% liked)

Python

6381 readers
60 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

๐Ÿ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

๐Ÿ Python project:
๐Ÿ’“ Python Community:
โœจ Python Ecosystem:
๐ŸŒŒ Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 7 points 1 day ago (5 children)

Path objects also override the / operator to join paths

This is both cool and gross... gives me C++ vibes (operator overloading abuse).

[โ€“] [email protected] 2 points 1 day ago

Scapy is another library where they redefined / to layer packets, such that you can write:

IP(dst="172.23.34.45") / UDP() / DNS(โ€ฆ)

Then Scapy has magic so that on serialisation, the UDP layer knows defaults to dport=53 if the upper layer is DNS, and it can access the lower layer to compute its checksum.

And don't forget that strings have a custom % (as in modulo) operator for formatting:

"Hello %s" %(username)

Of course in modern Python, f-strings will almost always be more convenient

load more comments (4 replies)