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

Thanks for explaining!
By the way, I’m TAAAT

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

Python

Thanks! 👌
Could you give a quick example of how you implement it in a real project?
I’m curious about the practical structure 🐍🛠️

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

Python

When building a large Python project, how do you structure your modules and packages for maximum maintainability 🐍🛠️?

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

Python

if you watch closely on my example above has_liver() actually not using cls which means it should/could be staticmethod instead. from here you might realize what OOP is as a paradigm.

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

Python

That said, a staticmethod does not need to be a pure function.

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

Python

Like a function that you need inside the instance which performs an operation but does not need a reference to the instance. A pure function.

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

Python

decorators are a new world for me... wow

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

Python

Functions bound to a class that do not need to access the attributes of the instance or which do not need a reference to a class. Basically functions with an association to a class.

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

Python

mhh... i think i understood but i'm not completely sure... can u show me an example if u can? However thx for the help which u are giving me 👍🏻❤️

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

Python

It allows you to get a reference to the class, with which you can create instances. Or do something else with.

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

Python

Right, new creates the instance, but maybe you want a method that creates it with some pre-defined values.

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

Python

Yes, that's what I meant to say, but it's harder for me to say it in English.

I know self and cls, cls is “new” to me because I discovered it not long ago and I will definitely learn more about it.

I know that there is only one class and that from it you can only create (infinite) instances that are saved in variables and therefore become objects (which have all the properties of the class and are instances).

I know that it is not possible to access the keywords of the language and that it is not possible to use keywords as variable names, just as it is not possible to use numbers for the same purpose.

I know the difference between class attributes and class instances: attributes are variables defined within the class and can only be used through instances of the class itself, while instances are variables outside the class that obtain its properties, attributes, and methods.

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

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

The approach depends on the type of application. But it helps to think in units that are responsible for the data retrieval and storage, logic and representation.

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

Python

Like the framework suggests. If you don't use a framework, then pretend like you're writing one.

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

Python

As soon as I can, I'll read everything carefully. Now i have to run 👍🏻😅

@Inchidi @c0x6a @notfromcambrigde @razorblade23 thx for the help ❤️❤️

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

Python

You have not scratched the surface yet 😁

Try making your custom one... (decorator i mean)
It should be more familiar once you realize how it works internally

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

Python

Pure functions are easy to test. They have an input and an output and no side-effects.

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

Python

Yeah, me personally use them almost never

But it can be useful when you want to add a method to some class it semanticly belongs to, but does not need any class/instance data to execute

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

Python

Like when you want to group functions. To keep things clean.

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

Python

Mhh ok, so cls is a class reference... but wtf u can make class methods which doesn't use self or cls? this is new for me

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

Python

While self references the specific instance of a class, @classmethod - cls references the class itself

There is also a @staticmethod which is for methods that do not need to use self or cls - they do not need class/instance data but kinda belong there semanticly

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

Python

oh so classmethod decorator allows to make methods which can create custom istances of the class?

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

Python

oh thx, this is what i asked, i knew that new() method was the instances maker... i knew wrong or i understood wrong what u wrote?

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

Python

And since those two different kinds of method get different arguments, it's crucial to understand the difference between them.

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

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 😅

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