PYPROGLIB Telegram 7083
😃 attrs: простота написания Python-классов без бойлерплейта

attrs — это Python-пакет, который снимает рутину при написании классов и автоматически реализует «ду́ндер»-методы (__init__, __repr__, __eq__ и др.).

📌 Используется даже NASA в миссиях на Марс с 2020 года!

Основная цель — писать лаконичный и корректный код без потерь производительности.

Пример:
from attrs import asdict, define, make_class, Factory

@define
class SomeClass:
a_number: int = 42
list_of_numbers: list[int] = Factory(list)

def hard_math(self, another_number):
return self.a_number + sum(self.list_of_numbers) * another_number

sc = SomeClass(1, [1, 2, 3])
print(sc) # SomeClass(a_number=1, list_of_numbers=[1, 2, 3])
print(sc.hard_math(3)) # 19
print(asdict(sc)) # {'a_number': 1, 'list_of_numbers': [1, 2, 3]}


attrs автоматически добавляет:
✔️ читаемый __repr__
✔️ методы сравнения
✔️ __init__ и управление аргументами
✔️ фабрики значений (Factory)
✔️ конструктор классов на лету (make_class)

📱 Репозиторий

🐸 Библиотека питониста

#буст
Please open Telegram to view this post
VIEW IN TELEGRAM
12👍4🔥3



tgoop.com/pyproglib/7083
Create:
Last Update:

😃 attrs: простота написания Python-классов без бойлерплейта

attrs — это Python-пакет, который снимает рутину при написании классов и автоматически реализует «ду́ндер»-методы (__init__, __repr__, __eq__ и др.).

📌 Используется даже NASA в миссиях на Марс с 2020 года!

Основная цель — писать лаконичный и корректный код без потерь производительности.

Пример:

from attrs import asdict, define, make_class, Factory

@define
class SomeClass:
a_number: int = 42
list_of_numbers: list[int] = Factory(list)

def hard_math(self, another_number):
return self.a_number + sum(self.list_of_numbers) * another_number

sc = SomeClass(1, [1, 2, 3])
print(sc) # SomeClass(a_number=1, list_of_numbers=[1, 2, 3])
print(sc.hard_math(3)) # 19
print(asdict(sc)) # {'a_number': 1, 'list_of_numbers': [1, 2, 3]}


attrs автоматически добавляет:
✔️ читаемый __repr__
✔️ методы сравнения
✔️ __init__ и управление аргументами
✔️ фабрики значений (Factory)
✔️ конструктор классов на лету (make_class)

📱 Репозиторий

🐸 Библиотека питониста

#буст

BY Библиотека питониста | Python, Django, Flask




Share with your friend now:
tgoop.com/pyproglib/7083

View MORE
Open in Telegram


Telegram News

Date: |

“Hey degen, are you stressed? Just let it all out,” he wrote, along with a link to join the group. Among the requests, the Brazilian electoral Court wanted to know if they could obtain data on the origins of malicious content posted on the platform. According to the TSE, this would enable the authorities to track false content and identify the user responsible for publishing it in the first place. SUCK Channel Telegram A Telegram channel is used for various purposes, from sharing helpful content to implementing a business strategy. In addition, you can use your channel to build and improve your company image, boost your sales, make profits, enhance customer loyalty, and more. bank east asia october 20 kowloon
from us


Telegram Библиотека питониста | Python, Django, Flask
FROM American