Похожие чаты

I'M applying a decorator on a method inside of a

class, how do i get that class inside of the decorator? i tried calling dir() on the method but i didn't find anything useful

14 ответов

11 просмотров
artemetra 🇺🇦-[less active] Автор вопроса

i can use func.__qualname__ to find the name of the class, but i'm looking for getting an actual reference to that class

artemetra 🇺🇦 [less active]
i can use func.__qualname__ to find the name of th...

You can either set it as a classmethod. Or (if you really want to), you can access it with: self.\_\_class\_\_ (without the backslashes, Cant find a way to display it correctly without them)

artemetra 🇺🇦-[less active] Автор вопроса
artemetra 🇺🇦 [less active]
here you go: self.__class__ 😁

I tried to make it as a code block. But it didn't work

artemetra 🇺🇦-[less active] Автор вопроса
shahar
You can either set it as a classmethod. Or (if yo...

do i set it as classmethod before or after my decorator? @classmethod @my_decorator def some_func(...) vs @my_decorator @classmethod def some_func(...)

artemetra 🇺🇦-[less active] Автор вопроса
shahar
second one

yeah, thanks :D i'll try out both the classmethod and the __class__

shahar
second one

so what is the difference btw them

You can apply decorators to classes too. But why do you want to access the method's class with the decorator, idk what are you trying to do, but it looks like it can get really messy quickly if you do that

artemetra 🇺🇦-[less active] Автор вопроса
harꭑony5 🐦‍🔥 ↺
You can apply decorators to classes too. But why d...

i know i can apply decorators to classes too and i'm actually using that. i'm trying out different solutions/desings as i'm currently very early in my project and unsure what's the best way to achieve what i need, thank you though

harꭑony5 🐦‍🔥 ↺
You can apply decorators to classes too. But why d...

does decorating a whole class means decorating the constructor

Fan / Ac
does decorating a whole class means decorating the...

You could even create a subclass of the decorated class inside the decorator and return it.

Похожие вопросы

Обсуждают сегодня

Hi everyone! I have a two-folded message to share today. First: updates and news, as we are being asked for those. We still want to go like we did the last 6 years: we w...
Marten | Unibright.io
31
Happy Friday and happy CartesiWeekly! This week on the list: 🪲 Bug Buster Update 🎥 Erick de Moura’s interview with Ornella from Web3TV 👽 Thriving Cartesi alien 🇧🇷 SBRC hackat...
Nida | Cartesi - Never DM first or ask for funds!
1
Скажите, можно ли как-то "переместить" динамический массив из одной переменной в другую? Скажем, переместить из TList<> в TArray<>. Именно переместить, а не скопировать. Если ...
Eugene Krasnikov (ᴊɪɴ x)
37
Oh.... Admins at the main TG is already muted me. How many months Sir you muted me? Or forever if you are here @Janevietani @JohnnySonic
Charles Dar
28
Вот еще криповенькая штука. uMain.pas(517,3) Warning: Case statement does not handle all possible cases И ЧО? 😂
Александр (Rouse_) Багель
20
комрады, че-та лыжы не едут var tmpFont: TFont; begin tmpFont:= TFont.Create; try case rgFontColor.ItemIndex of 0: tmpFont.Color:= clWindowText; 1: tmpFo...
Ed Doc
34
.model small .stack 100h .data a db 'Hello, World!', '$' ; исходная строка b db 20 dup(?) ; строка b с запасом на максимальную длину .code main: ...
Алексей -man
3
Интересно, нет ли какого-то способа получить из dll не адрес самой метки, а адрес со смещением?
The Bird of Hermes
54
вопрос, кого посмотреть в ютубе или где почитать про указатели чтобы раз и навсегда запомнить зачем они нужны и как правильно ими пользоваться? поделитесь хорошими ресурсами, ...
-
14
М-да. Почему бы просто со stringlist не работать?
Michael Longneck
23
Карта сайта