Cerca

Heus ací els resultats de la cerca.

3.1 Advanced techniques of creating and serving exceptions
14 Resultats, Darrera modificació:
Error: list index out of range </code> Sooner or later, every Pythonista will write a code that raise... in the object. * **end** – the index after the last invalid data in the object. See the output of ... xception object in a handy and consistent way for later processing like logging, etc. Look at the fol... an exception or error in most of the programming languages): <code ; output> Traceback (most recent c
1.2 Working with class and instance data – instance variables
9 Resultats, Darrera modificació:
tialization, performed by the __init__ method, or later at any moment of the object's life. Furthermor... return message class FixedPhone(Phone): last_SN = 0 def __init__(self, number): super().__init__(number) FixedPhone.last_SN += 1 self.SN = 'FP-{}'.format(FixedPhone.last_SN) class MobilePhone(Phone): last_SN = 0
4.1 Shallow and deep copy operations
9 Resultats, Darrera modificació:
s. Specifically, you'll learn about: * object: label vs. identity vs. value; * the id() function ... * finally a variable, which you should treat as a label or name binding, is created, and this label refers to a distinct place in the computer memory. Wh... t object 'identity'? Why are the object value and label not enough? The built-in ''id()'' function re
2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
8 Resultats, Darrera modificació:
ays true, but we'll discuss this issue more a bit later. {{ :info:cursos:pue:python-pcpp1:pasted:2023... ere: <code python>class Vehicle: pass class LandVehicle(Vehicle): pass class TrackedVehicle(LandVehicle): pass</code> All the presented cla... *Vehicle** class is the superclass for both the **LandVehicle** and **TrackedVehicle** classes; * th
4.2 Serialization of Python objects using the pickle module
8 Resultats, Darrera modificació:
you will learn how to persist Python objects for later use. **Pickling** is the process of preservin... red saving the output of your data processing for later use? The simplest way to persist outcomes is ... module, you can 'pickle' your Python objects for later use. The 'pickle' module is a very popular an... ckle module: <code python> import pickle </code> Later you can see that the file handle 'file_out' is
2.1 Python core syntax
6 Resultats, Darrera modificació:
se, the '+' operator is just a handy example, and later on we'll discuss other operators. In Python, ... /code> <code ; output>Traceback (most recent call last): File "core#010.py", line 11, in print(... tation for the built-in integer type. Look at the last lines of the output – it contains information a... before doing it, or else raise an exception. === LAB 1 * Create a class representing a time interva
2.4 Decorators
6 Resultats, Darrera modificació:
ng function returns a function that can be called later. Of course, the **decorating** function does ... we decorate classes. We'll talk about this a bit later. So from now on, the term 'decorator' will be... ction.__name__)) return function </code> The last lines are responsible for both method invocatio... would be packed with strong cardboard </code> == Lab === Objectives * Improving the student's skill
2.7 Encapsulation
6 Resultats, Darrera modificació:
door ( **object** ) that protects access to your laundry ( **attribute values** ) while your applianc... ols ( **methods** ) that allow you to manage your laundry, or even see it (many wash machines are equi... So, while the washing machine is processing your laundry, you are not able to directly access the laundry. This is how attribute encapsulation works. An
5.1 Metaprogramming
6 Resultats, Darrera modificació:
ssed his feelings about metaclasses in the **comp.lang.python** newsgroup on 12/22/2002: //[metaclass... izing a new class instance. Classes receive a new layer of logic. Now that we know what’s happening u... eated classes to conform with selected rules. == LAB === Scenario * Imagine you’ve been given a tas... tiation_time) print(f"Hora d'instanciament de la classe {type(self).__name__}: {human_readable.str
2.6 Abstract classes
5 Resultats, Darrera modificació:
n is considered to be a very flexible programming language, but that doesn’t mean that there are no co... s __all__ abstract methods. When we’re designing large functional units, in the form of classes, we s... lcome to Green Field! Traceback (most recent call last): (...) bp = BluePrint() TypeError: Can't i... lcome to Green Field! Traceback (most recent call last): (...) rf = RedField() TypeError: Can't in
2.8 Composition vs Inheritance - two ways to the same destination
5 Resultats, Darrera modificació:
is called an **is a** relation. Examples: * a Laptop **is a** (specialized form of) Computer; * ... is called a **has a** relation. Examples: * a Laptop **has a** network card; * a Hovercraft **ha... oad some data using a slow dialup connection; * later, we equip our personal computer with a more ad... ct – we just arm it with a new component; * the last steps are about arming our old computer with a
2.3 Extended function argument syntax
3 Resultats, Darrera modificació:
amed *args and %%**%%kwargs) should be put as the last two parameters in a function definition. Their ... items. If you’ve ever programmed in the C or C++ languages, then you should remember that the asteris... 50, 'argument2': '66'} <class 'dict'> </code> The last example in this section shows how to combine *a
2.5 Different faces of Python methods
3 Resultats, Darrera modificació:
eated instances or the serial number given to the last produced object, or we modify the state of the ... ify the state of objects or classes, because they lack the parameters that would allow this. <code py... and a static method is only a utility method. == lab === Objectives * improving the student's skill
2.9 Inheriting properties from built-in classes
3 Resultats, Darrera modificació:
u can still access those attributes and methods. Later, you can override the methods by delivering yo... is method calls the check_value_type() method and later calls the genuine method ''%%__setitem__%%'' w... lidating snippet into a function, reformulate the last condition, and use it as a helper function. <c
1.1 Classes, Instances, Attributes, Methods — introduction
2 Resultats, Darrera modificació:
ct (functions, modules, lists, etc.). In the very last section of this module, you'll see that even cl... uack** is an attribute of the 'method' type. === LAB Python allows for variables to be used at the in