python | Unsorted

Telegram-канал python - Python

135201

You will be muted until you read the rules. Read them! @Rules_for_Python A group about the Python programming language. Offtopic things go here: @pythonofftopic Resources to learn python: @pythonres Group for Hy: @hylang Selenium: @SeleniumPython

Subscribe to a channel

Python

Because class is reserved keyword in the language. You cannot use it as the name for a variable. Or perhaps you can, but in that case you also shouldn't.

Читать полностью…

Python

But sometimes you want a method that creates an instance, for example. Such a method will not be called from an instance, but from the class. And it needs a reference to the class. That's what a classmethod is for.

Читать полностью…

Python

Can you send me the link of the Api

Читать полностью…

Python

ok thx

Thank you both, actually. 👍🏻

Читать полностью…

Python

after that, when you have all things clear, you can use/mix them together and you'll understand what @classmethod does

Читать полностью…

Python

🤔 looks like you need to understand OOP concepts first, that's your first task

Читать полностью…

Python

Honestly, idk. I just had my doubts because I don't know decorators very well.

Читать полностью…

Python

why did you think that?

Читать полностью…

Python

the question here is "WHY are you using @classmethod ?"

Читать полностью…

Python

anyone could link me a guide to use decorators? i don't understand when i should use them
this is my case:

class Foo:

elements = []

@classmethod
def _adder(self, new_elements):
self.elements.extend(new_elements)

@classmethod
def _remover(self, elements):
for e in elements: elements.remove(e) # Actually i don't remember exactly the method

def update_elements(self, elements, action):
match action:
case 'add': self._adder(elements)
case 'rmv': self._remover(elements)

the class in brief

Читать полностью…

Python

If you are having issues installing it, post your question in the @pythonofftopic group; there might be people who can help you.

Читать полностью…

Python

Win7 only supports up to version 3.8.10 of Python.

Читать полностью…

Python

Please python 3.8 versiya

Читать полностью…

Python

Setup issues go into @pythonofftopic. And you really should not use a Python version that does not receive any updates any more (unsupported).

Читать полностью…

Python

python.org/downloads

Читать полностью…

Python

That's why

class Foo:
@classmethod
def foo(self):
...

is always wrong. When you have a classmethod, you get a reference to the class, not to an instance. We don't call that self anymore, but cls.

Читать полностью…

Python

cj is right. You need to understand OOP first. You know the difference between a class and an instance?

Читать полностью…

Python

oh, i had no idea, yeah, i really need to study better what decorators does 😅

Читать полностью…

Python

well classmethod is a built-in, so might be a bit different with decorators in general. decorator itself basically "wrapper for functions" and its for any functions and not only class methods.

Читать полностью…

Python

and if you want to learn about decorators you can do it separately, no need to mess with OOP on them

Читать полностью…

Python

sell the liver to buy an iPhone now

Читать полностью…

Python

you dont need to use classmethod for your example above. classmethod used when you need a function that related to a class but not related with the class data. eg:

class Person:
liver_count = 2
@classmethod
def has_liver(cls):
return True
def remove_liver(self):
if self.liver_count == 1: raise PersonNeedALiverError()
self.liver_count -= 1

Person.has_liver() # to use class method

p = Person()
p.remove_liver()

Читать полностью…

Python

Because, as you can see from my code, the editor methods receive elements from an update method that calls them based on what needs to be done, so I thought they should be preceded by the @classmethod decorator.

Читать полностью…

Python

@Inchidi told me i don't have to use @classmethod but i didn't understood the motivation and so when i should use it and the decorators in general

Читать полностью…

Python

❎ ‎clouded pardoned ‎ㅤ [6468398014] for
1/3: ‎[Python] [Automated] Rule 1️⃣: Speak English.

Читать полностью…

Python

Nothing we can do about it. And it's the other around. Python does not support certain Windows versions.

Читать полностью…

Python

/channel/Python/2241299

Читать полностью…

Python

Read this please:
http://www.catb.org/~esr/faqs/smart-questions.html

Читать полностью…

Python

That's a bit too little to work with.

Читать полностью…

Python

Please pythonn versiya 3.8 windows7 32 bit Please send

Читать полностью…
Subscribe to a channel