Modern Python ????

Published on Slideshow
Static slideshow
Download PDF version
Download PDF version
Embed video
Share video
Ask about this video

Scene 1 (0s)

Modern Python ?. Alla scoperta delle ultime novità di (C)Python.

Scene 2 (8s)

About me. ? Studente di Informatica (1° anno) ? Freelancer occasionale ? Appassionato di Python.

Scene 3 (22s)

Punti salienti ?. Tips & Tricks __format__ __matmul__ __reversed__ functools.lru_cache contextlib.suppress contextlib.contextmanager (+ async) Type hinting Pathlib Generatori Async Pattern Matching Walrus Operator.

Scene 4 (33s)

Tips & Tricks ✨.

Scene 5 (40s)

__format__. Gestione dei format specifier Chiamato ad ogni format() /f-string Format specifier personalizzati.

Scene 6 (52s)

__matmul__. Operatore di moltiplicazione matriciale Origine: NumPy Codice più conciso Evitare di abusarne se si tiene al posto di lavoro!.

Scene 7 (1m 13s)

__reversed__. Iterazione inversa tramite generatori: Non induce copie [::-1] è oscuro, reversed() è esplicito Nota : Non funziona con i generatori!.

Scene 8 (1m 24s)

@lru_cache. Minimalmente intrusivo Estremamente efficace Nota: Esiste anche functools. cache senza il meccanismo LRU!.

Scene 9 (1m 33s)

Memoizzazione con @lru_cache — Dimostrazione.

Scene 10 (1m 45s)

Non elegante Verboso Non flessibile Breve Conciso Esplicito.

Scene 11 (1m 53s)

Più conciso rispetto a due metodi __enter__ ed __exit__ Supporto async: contextlib.asynccontextmanager.

Scene 12 (2m 14s)

Type Hinting. MY NEW 15GREAT, FS A REGARDING T,'Æ: > I10.5 (10) > 03] > 2+7 (2/0) NAN (2/0)+2 NAP FRISE TRUE NAN.ooonDØC013 RANGE(Ø 12 2+2 FLOOR(lO.5).

Scene 13 (2m 25s)

Type Hinting - Unioni (prima). ✍️ Lungo da scrivere ? Verboso.

Scene 14 (2m 33s)

Type Hinting - Unioni (dopo). ? Breve ✨ Elegante ? P yth onico! Nota : Richiede Python 3.10.

Scene 15 (2m 43s)

Type Hinting - Alias. Type hint: opzionale Miglior supporto ai type checker Più elegante.

Scene 16 (2m 52s)

Type Hinting - Generic alias. Note : Non possono essere passati a i sinstance() Python non controlla il tipo dei valori a runtime repr() e str() mostrano gli argomenti generici.

Scene 17 (3m 9s)

Type Hints - Coroutines (Bonus!). import asyncio async def coro(name: str, delay: int) -> None: is sleeping for seconds! " ) await asyncio.sleep(delay) # Callable[[str, int], Coroutine[Any, Any, Any]].

Scene 18 (3m 22s)

Pathlib. 291.dcc Untitled 136 l)nidkd 13B Qb2.docx Ontdled 139. cbcx Vnttld qo ADRß5.jf3 292e Unt;tld 2143.Joc Untitled 2q3 OHMY@ NEVER IN a-SE's ØCLMENTS.

Scene 19 (3m 32s)

File Handling - Alla vecchia maniera ?. TART! AFTER TÆ ØLER? THItKT<RE'S NO ACTURL filEsx'STB•1S. ITS SO TAO!.

Scene 20 (3m 52s)

File Handling - Il futuro è qui ?. ? Conciso ✨ Elegante ? Nella stdlib.

Scene 21 (4m 9s)

Generatori Async ⚙️.

Scene 22 (4m 15s)

import time def ticker(to: tnt, delay: for t in range(to): yield i time . sleep( delay ) for t in delay= print(i) tnt): 1):.

Scene 23 (4m 22s)

import time import threading def ticker(to: int, delay: for in range(to): yield time. sleep(delay) int): def main( ) : for t in ticker (10, print(i) delay= 1): threading . Thread( target=matn) . run( ).

Scene 24 (4m 31s)

import asyncio async def ticker (to: tnt, delay: tnt): for t in range(to): yield await asyncto.sleep(delay) async def main( ) : async for in ticker(10, print(t) asyncto. ) ) delay—I ) :.

Scene 25 (4m 45s)

Pattern Matching.

Scene 26 (4m 51s)

Pattern Matching (prima). Verboso Poco Elegante Ripetitivo.

Scene 27 (5m 3s)

Pattern Matching (dopo). Conciso Elegante Flessibile Non supporta espressioni:.

Scene 28 (5m 15s)

Pattern Matching - Bonus ?. match event. get( ) : case handle_click_at(x, y) case KeyPress( ) I Quit(): game. quit( ) case KeyPress( arrow" ) : game. go _ north( ) case KeyPress( ) : pass # Ignore other keystrokes case other event: raise ValueError(f"Unrecognized event: " ).

Scene 29 (5m 29s)

E infine … Il tricheco!. Raffinato ? Conciso.

Scene 30 (5m 36s)

Occhio alle parentesi!*. *Nessun tricheco è stato maltrattato per la realizzazione di questa presentazione.

Scene 31 (5m 45s)

Grazie per aver partecipato! ?. https://nocturn9x.space.