Cerca

Heus ací els resultats de la cerca.

2.4 Decorators
50 Resultats, Darrera modificació:
* the measurement of execution time; * message logging; * thread synchronization; * code refact... heory. So, let's create a function – ''simple_hello()'' is one of the simplest functions we could thi... rate it in a moment. <code python> def simple_hello(): print("Hello from simple function!") </code> <code python> def simple_decorator(function):
3.1 Advanced techniques of creating and serving exceptions
40 Resultats, Darrera modificació:
execution of a program that disrupts the normal flow of the program's instructions. Plan for the mod... continue. Python provides effective tools that allow you to **observe exceptions, identify them and h... y have met an exception error message like the following: <code ; output> IndexError: list index out o... ld use the ''try: problematic_code'' except code block to surround the "problematic" piece of code. In
4.1 Shallow and deep copy operations
40 Resultats, Darrera modificació:
= 4.1 Shallow and deep copy operations == Copying objects using shallow and deep operations In this module, you’ll learn... * the id() function and the is operand; * shallow and deep copies of the objects. It’s hard to im... les. As variables are fundamental elements that allow us to cope with objects, let's talk in detail ab
2.6 Abstract classes
38 Resultats, Darrera modificació:
es or an order in a class hierarchy. When you develop a system in a group of programmers, it would be ... a dedicated Python module to validate if the developer has implemented a subclass that overrides __al... tract class, because abstract classes partially allow us to implement classes by delivering concrete d... application, even after the main application development is finished. Let's start with a typical cla
2.8 Composition vs Inheritance - two ways to the same destination
37 Resultats, Darrera modificació:
same destination So far we've been using and following the inheritance concept when modeling our cla... s and **all** properties of the base class, and allows a subclass to extend everything that has been i... he top (the superclass) while its descendants are located below (the subclasses). What could be inherited in this “Vehicles” structure? All classes deri
2.9 Inheriting properties from built-in classes
34 Resultats, Darrera modificació:
odifications for the selected methods. In the following example, we’ll create an implementation of ou... we focus on the problem and not on type control. Look at the code presented in the editor pane. <cod... an element to the end of the list. This method follows the previous way of dealing with a new element;... built-in dictionary, which will be equipped with logging mechanisms for details of writing and readin
2.1 Python core syntax
22 Resultats, Darrera modificació:
we have been using Python core operations that allow us to operate on strings, lists, integers, and floats. It’s natural for us to formulate expressions ... issubclass() and a few more elements. Python allows us to employ operators when applied to our objects, so we can use core operators on our objects. L
4.2 Serialization of Python objects using the pickle module
21 Resultats, Darrera modificació:
, what can be pickled and then unpickled? The following types can be pickled: * None, booleans; * integers, floating-point numbers, complex numbers; * strings,... file should be created. Remember to run the code locally. <code python> import pickle a_dict = dict(... starts with the import statement responsible for loading the pickle module: <code python> import pick
2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
17 Resultats, Darrera modificació:
cts the shape of the inheritance diagram — take a look at the picture. There is the top-most supercla... ot define the method ''info()'', so Python has to look for it in the class hierarchy; * **class D** ... uperclasses in the subclass definition. In the following example, class D is based on classes B and C,... ding via fax. The methods are delivered by the following classes: * scan(), delivered by the Scanner
5.1 Metaprogramming
16 Resultats, Darrera modificació:
ven implementing the properties protocol. It may look like syntactic sugar, because in many cases metaprogramming allows programmers to minimize the number of lines of code to express a solution, in turn reducing development time. But the truth is that this technique ... tools could be applied to your code to make it follow specific programming patterns, or to help you cr
1.1 Classes, Instances, Attributes, Methods — introduction
13 Resultats, Darrera modificació:
resent in most computer applications because it allows programmers to model entities representing real-life objects. Moreover, OOP allows programmers to model interactions between objec... anding of common terms, we should agree on the following definitions: * class — an idea, blueprint,... ares methods used to perform actions. * The following issues will be addressed during this and the
2.5 Different faces of Python methods
13 Resultats, Darrera modificació:
worth emphasizing and remembering that ''self'' allows you to refer to the instance. Of course, it follows that in order to successfully use the instance ... internal%%'', and the ''get_internal()'' method allows you to read the instance variable specific to t... t you must do it consistently in your code. It follows from the convention that //self// literally mea
1.2 Working with class and instance data – instance variables
11 Resultats, Darrera modificació:
ny way. The word instance suggests that they are closely connected to the objects (which are class ins... riable, you should address the variable in the following way: objectdotvariable_name. Let's look at how the instance variable is created and accessed in the code presented below. <code python> class Demo: def __init__(sel
4.3 Making Python objects persistent using the shelve module
11 Resultats, Darrera modificació:
serializing many objects. Sound familiar? An analogy to the rack with shelves in the pantry is a correct one. Looks delicious, doesn’t it? Using shelve is quite ... eady for action, so let's insert a few items and close the shelve object. <code python> my_shelve['USD... {'code':'Japanese yen', 'symbol': '¥'} my_shelve.close() </code> Now let's open the shelve file to de
2.7 Encapsulation
10 Resultats, Darrera modificació:
nge your class implementation from a class that allows simple and direct access to attributes to a cla... s use of your objects. Let's start with a few analogies from real life: Imagine a washing machine doo... You have a set of controls ( **methods** ) that allow you to manage your laundry, or even see it (many... g the liquid level to a negative value. Python allows you to control access to attributes with the bu
2.3 Extended function argument syntax
5 Resultats, Darrera modificació: