Cerca

Heus ací els resultats de la cerca.

2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
26 Resultats, Darrera modificació:
and expresses the fundamental relationships between classes: superclasses (parents) and their subclas... e going to show you how the mutual relations between the super- and subclasses work. We can say that:... classical problem named the diamond problem, or even the deadly diamond of death. The name reflects th... nfo(), which part of the code would be executed then? Python lets you implement such a class hierarch
2.9 Inheriting properties from built-in classes
26 Resultats, Darrera modificació:
wn functionalities inherited from its parent or even parents and you can still access those attributes... le), and control over the types of elements is given to the mechanisms of the new class. As a result, when solving a domain problem, we focus on the problem... a ValueError exception is raised; * an overridden method ''%%__setitem__%%'', which is a magic meth
1.2 Working with class and instance data – instance variables
22 Resultats, Darrera modificació:
Instance variables This kind of variable exists when and only when it is explicitly created and added to an object. This can be done during the object's i... ble, simply access it using the class name, and then provide the variable name. <code python> class D... ble contents of d1: {} </code> **Conclusion**: when you want to read the class variable value, you ca
2.6 Abstract classes
22 Resultats, Darrera modificació:
nctionalities or an order in a class hierarchy. When you develop a system in a group of programmers, i... eprint for other classes, a kind of contract between a __class designer__ and a __programmer__: * t... , but if any of the methods is an abstract one, then the class becomes abstract. == What is an abstra... ase music format and corresponding methods for “open”, “play”, “get details”, “rewind”, etc., to maint
2.1 Python core syntax
21 Resultats, Darrera modificació:
= 2.1 Python core syntax So far we have been using Python core operations that allow us to operate on ... data types. Now, we'll use the same function ''len()'' to get a number of elements of a tuple, list,... pecific operations **on different** data types, when operations are formulated using **the same** operators or instructions, or even functions. Python core syntax covers: * opera
5.1 Metaprogramming
21 Resultats, Darrera modificació:
plementing decorators, overriding operators, or even implementing the properties protocol. It may loo... Tim Peters, the Python guru who authored the **Zen of Python**, expressed his feelings about metacla... anding of what is happening under Python's hood when classes are created. In Python, a metaclass is a... callable objects. Class decorators are applied when classes are instantiated; * metaclasses redirec
1.1 Classes, Instances, Attributes, Methods — introduction
19 Resultats, Darrera modificació:
OOP allows programmers to model interactions between objects in order to solve real-life problems in a... rendered in a web browser created with OOP, and even the mouse cursor image is displayed using an appl... instance — an instantiation of the class; very often used interchangeably with the term 'object'; * ... ry last section of this module, you'll see that even classes are instances. Why is everything in Pyth
4.1 Shallow and deep copy operations
19 Resultats, Darrera modificació:
nd objects, and possible ways of copying them. When you spot the following clause: <code python> a_li... 's memory. Now the object has its identity; * then the object is populated with other objects. Now o... function is rarely used in applications. More often you’ll use it to debug the code or to experiment ... eachable in the scope in which the variable has been defined. You should remember to avoid such situat
2.5 Different faces of Python methods
18 Resultats, Darrera modificació:
ferent faces of Python methods Until now, we’ve been implementing methods that have performed operatio... lf''. The name of the parameter ''self'' was chosen arbitrarily and you can use a different word, but... methods bound to the class, not to the object. When can this be useful? There are several possibilit... mber of created instances or the serial number given to the last produced object, or we modify the sta
4.2 Serialization of Python objects using the pickle module
16 Resultats, Darrera modificació:
ld of Pythonistas. So, what can be pickled and then unpickled? The following types can be pickled: ... t containing a string, an integer, and a list. When you run the code presented in the right pane, a n... 'symbol': '$'} a_dict['JPY'] = {'code':'Japanese yen', 'symbol': '¥'} a_list = ['a', 123, [10, 100, 1000]] with open('multidata.pckl', 'wb') as file_out: pickle.d
2.4 Decorators
15 Resultats, Darrera modificació:
rating function. The same principle is applied when we decorate classes. We'll talk about this a bit ... before and after a call to a wrapped object or even to prevent its execution, depending on the circum... ook like the code presented in the right pane. When you run the code, the result should be: <code ; o... etermines the order of the executed decorators. When your function is decorated with multiple decorato
4.3 Making Python objects persistent using the shelve module
15 Resultats, Darrera modificació:
ase (dbm) requires strings. Therefore, you can open your shelved data file and access your pickled objects via the keys the way you do when you access Python dictionaries. This could be more convenient for you when you’re serializing many objects. Sound familiar?... <code python> import shelve my_shelve = shelve.open('first_shelve.shlv', flag='w') </code> The meani
2.7 Encapsulation
14 Resultats, Darrera modificació:
s** ) that allow you to manage your laundry, or even see it (many wash machines are equipped with a tr... ank; this time it’s a more IT-related example: When your money ( **attribute value** ) is deposited i... ixed with a double underscore) in a direct way, then remember that this behavior is **unpythonic**. T... tes a method which will be called automatically when another object wants to read the encapsulated att
2.8 Composition vs Inheritance - two ways to the same destination
13 Resultats, Darrera modificació:
two ways to the same destination So far we've been using and following the inheritance concept when modeling our classes to represent real-life issues. ... ted programming that models a tight relation between two classes: the base class and the derived class... allows a subclass to extend everything that has been inherited. By extending a base class, you are cre
3.1 Advanced techniques of creating and serving exceptions
13 Resultats, Darrera modificació:
exception. == Exceptions - short introduction When Python executes a script and encounters a situati... s raises an exception (or that an exception has been raised) when it has no idea what do to with your code. What happens next? * the raised exception ... by Python; * otherwise, if the exception is taken care of and **handled** properly, the suspended p
2.3 Extended function argument syntax
7 Resultats, Darrera modificació: