Cerca

Heus ací els resultats de la cerca.

3.1 Advanced techniques of creating and serving exceptions
58 Resultats, Darrera modificació:
ring the execution of a program that disrupts the normal flow of the program's instructions. Plan for... es a script and encounters a situation that it cannot cope with, it: * stops your program; * crea... 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 happen
2.7 Encapsulation
32 Resultats, Darrera modificació:
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
5.1 Metaprogramming
27 Resultats, Darrera modificació:
herent API (Application Programming Interface). Another example of metaprogramming is the **metaclass... em, you don't (the people who actually need them know with certainty that they need them, and don't ne... 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
2.4 Decorators
26 Resultats, Darrera modificació:
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_decorator()'', which is more interesting as it accepts an ob... ed a simple decorator – a function which accepts another function as its only argument, prints some de
2.9 Inheriting properties from built-in classes
24 Resultats, Darrera modificació:
eated class has the advantage of all of the well-known functionalities inherited from its parent or ev... serial numbers of sold tickets. Sound reasonable enough? Your new class will be based on the Python... 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 intege
4.2 Serialization of Python objects using the pickle module
23 Resultats, Darrera modificació:
omes. It’s a very simple thing to do way which is not suitable for persisting sets of different types ... formation necessary to reconstruct the object in another Python script. This reverse process is calle... 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
2.6 Abstract classes
21 Resultats, Darrera modificació:
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... tions and the completeness would be validated by another, dedicated module. The programmer delivers th... tract class. This means that abstract classes are not limited to containing only abstract methods – so
2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
20 Resultats, Darrera modificació:
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
1.2 Working with class and instance data – instance variables
18 Resultats, Darrera modificació:
set of variables – they don't interfere with one another in any way. The word instance suggests that t... ected to the objects (which are class instances), not to the classes themselves. To get access to the ... dependently, because the printed values differ. Another snippet shows that instance variables can be ... e_var = value d1 = Demo(100) d2 = Demo(200) d1.another_var = 'another variable in the object' print
2.5 Different faces of Python methods
18 Resultats, Darrera modificació:
= 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.3 Extended function argument syntax
15 Resultats, Darrera modificació:
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... ument values are passed to the standard output. Another interesting example can be presented with a l
4.1 Shallow and deep copy operations
15 Resultats, Darrera modificació:
: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
14 Resultats, Darrera modificació:
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... eling every vehicle object, so the polymorphism, another pillar of the OOP allowing you to call the ''... be hard to understand, debug, and extend. This phenomenon is known as the class explosion problem, and
2.1 Python core syntax
12 Resultats, Darrera modificació:
oncatenation; we are able to add integers and we know what the result should be, all done by using 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... ethods delivered by specific classes. So Python knows what to do when the interpreter spots the '+' o
1.1 Classes, Instances, Attributes, Methods — introduction
7 Resultats, Darrera modificació:
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... ritance to get a more specialized class based on another class. Additionally, your classes could be u... ta with the code. If you run the code, there are no visible effects. The class has been defined, but
4.3 Making Python objects persistent using the shelve module
6 Resultats, Darrera modificació: