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
Thanks! 👌
Could you give a quick example of how you implement it in a real project?
I’m curious about the practical structure 🐍🛠️
When building a large Python project, how do you structure your modules and packages for maximum maintainability 🐍🛠️?
Читать полностью…
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.
That said, a staticmethod does not need to be a pure function.
Читать полностью…
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.
Читать полностью…
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.
Читать полностью…
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 👍🏻❤️
Читать полностью…
It allows you to get a reference to the class, with which you can create instances. Or do something else with.
Читать полностью…
Right, new creates the instance, but maybe you want a method that creates it with some pre-defined values.
Читать полностью…
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.
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.
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.
Читать полностью…
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.
Читать полностью…
Like the framework suggests. If you don't use a framework, then pretend like you're writing one.
Читать полностью…
As soon as I can, I'll read everything carefully. Now i have to run 👍🏻😅
@Inchidi @c0x6a @notfromcambrigde @razorblade23 thx for the help ❤️❤️
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
Pure functions are easy to test. They have an input and an output and no side-effects.
Читать полностью…
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
Like when you want to group functions. To keep things clean.
Читать полностью…
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
Читать полностью…
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
oh so classmethod decorator allows to make methods which can create custom istances of the class?
Читать полностью…
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?
Читать полностью…
And since those two different kinds of method get different arguments, it's crucial to understand the difference between them.
Читать полностью…
That's why
class Foo:
@classmethod
def foo(self):
...
self anymore, but cls.
Читать полностью…
cj is right. You need to understand OOP first. You know the difference between a class and an instance?
Читать полностью…
oh, i had no idea, yeah, i really need to study better what decorators does 😅
Читать полностью…