Cerca
Heus ací els resultats de la cerca.
Resultats de text complet:
- 2.7 Encapsulation
- dea: direct access to the object attribute should not be possible, but you can always invoke methods, ... es: * the code calling the proxy methods might not realize if it is "talking" to the real attribute... t is most important –consumer implementation does not have to be changed; by consumer we understand so... shing machine is processing your laundry, you are not able to directly access the laundry. This is how
- 2.4 Decorators
- sses. We'll talk about this a bit later. So from now on, the term 'decorator' will be understood as a... imple_hello" Hello from simple function! </code> Now let's create another function, ''simple_decorato... example, as the arguments were just printed, but not processed further. A nested function (internal_... tor', because it can handle different materials. Note that our decorator is enriched with one more fu
- 4.2 Serialization of Python objects using the pickle module
- omes. It’s a very simple thing to do way which is not suitable for persisting sets of different types ... ickled? The following types can be pickled: * None, booleans; * integers, floating-point numbers... es!) * references to functions and classes, but not their definitions. Let's pickle our first set o... open('multidata.pckl', 'wb') as file_out: </code> Now it’s time to persist the first object with the '
- 2.9 Inheriting properties from built-in classes
- ing a domain problem, we focus on the problem and not on type control. Look at the code presented in ... heck_value_type(value): if type(value) is not int: raise ValueError('Not an integer type') def __setitem__(self, index, value): ... ethod a few times. In case the argument's type is not an integer, a ValueError exception is raised;
- 3.1 Advanced techniques of creating and serving exceptions
- ring the execution of a program that disrupts the normal flow of the program's instructions. Plan for... or that an exception has been raised) when it has no idea what do to with your code. What happens nex... raised exception expects somebody or something to notice it and take care of it; * if nothing happens to take care of the raised exception, the program
- 2.5 Different faces of Python methods
- = 2.5 Different faces of Python methods Until now, we’ve been implementing methods that have performed... ol methods, extending our ability to use classes, not necessarily requiring the creation of class inst... ke class variables, work on the class itself, and not on the class objects that are instantiated. You ... can say that they are methods bound to the class, not to the object. When can this be useful? There
- 2.6 Abstract classes
- ng language, but that doesn’t mean that there are no controls to impose a set of functionalities or an... t must be implemented by just declaring them, but not defining them in detail. Such methods are called... tract class. This means that abstract classes are not limited to containing only abstract methods – so... thod is a method that has a declaration, but does not have any implementation. We'll give some example
- 2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
- hat inheritance is a way of building a new class, not from scratch, but by using an already defined re... neral (more abstract) than any of its subclasses. Note that we've presumed that a class may only have one superclass — this is not always true, but we'll discuss this issue more a... s</code> All the presented classes are empty for now, as we're going to show you how the mutual relat
- 5.1 Metaprogramming
- the type of the metaclass ''type'' is ''type'' – no, that is not a typo. {{ :info:cursos:pue:python-pcpp1:pasted:20231104-102014.png }} To extend the a... ibute '__weakref__' of 'Dog' objects>, '__doc__': None} object "dog" attributes: {} </code> The same... ibute '__weakref__' of 'Dog' objects>, '__doc__': None} </code> The more complex example that dynamic
- 4.1 Shallow and deep copy operations
- :pue:python-pcpp1:pasted:20231026-143815.png }} (Note that an assignment statement is being used, so ... his example) is created in the computer's memory. Now the object has its identity; * then the object is populated with other objects. Now our object has a value; * finally a variable, ... ct 'identity'? Why are the object value and label not enough? The built-in ''id()'' function returns
- 2.8 Composition vs Inheritance - two ways to the same destination
- s:pue:python-pcpp1:pasted:20231023-022208.png }} Note: the hierarchy grows from top to bottom, like tree roots, not branches. The most general, and the widest, clas... the antipatterns of programming. Inheritance is not the only way of constructing adaptable objects. ... a change is applied to the engine object, it does not influence the “Car” class object structure; *
- 1.2 Working with class and instance data – instance variables
- ected to the objects (which are class instances), not to the classes themselves. To get access to the ... modifying the instance variable of any object has no impact on all the remaining objects. Instance var... iable', '__dict__': , '__weakref__': , '__doc__': None} </code> As a class variable is present before... ass variable is defined outside the object, it is not listed in the object's %%__dict__%%. <code pyth
- 2.3 Extended function argument syntax
- s may require a specific number of arguments with no exclusions; we have to pass a required number of ... ined default values for some parameters, so we do not have to pass all arguments as missing arguments,... l ones are the first ones on the arguments list. Now let’s get familiar with the functions that can a... ** *args** – refers to a tuple of all additional, not explicitly expected positional arguments, so arg
- 2.1 Python core syntax
- the “+” operator, but on respective data types. Now, we'll use the same function ''len()'' to get a ... m of the weights of the Person class objects does not exceed the safety limit, your elevator should al... t phrase). Dunders indicate that such methods are not called directly, but called in a process of expr... thod. These methods must be delivered by a class (now it’s clear why we treat classes as blueprints) t
- 1.1 Classes, Instances, Attributes, Methods — introduction
- structured manner. Imagine that the text you are now reading was rendered in a web browser created wi... e class that was used to instantiate the object. Now that we’re starting to discuss more advanced OOP... ta with the code. If you run the code, there are no visible effects. The class has been defined, but there is no code making use of it — that’s why you see no eff