Cerca

Heus ací els resultats de la cerca.

2.4 Decorators
19 Resultats, Darrera modificació:
function so that the **decorating** function can call the passed function. The decorating function retu... re used to perform operations before and after a call to a wrapped object or even to prevent its execut... _decorator(function): print('We are about to call "{}"'.format(function.__name__)) return funct... esult should be: <code ; output> We are about to call "simple_hello" Hello from simple function! </code
2.6 Abstract classes
15 Resultats, Darrera modificació:
ract methods**. * The programmer has to deliver all method definitions and the completeness would be ... reason is: we want our code to be polymorphic, so all subclasses have to deliver a set of their own method implementations in order to call them by using common method names. Furthermore, ... loper has implemented a subclass that overrides __all__ abstract methods. When we’re designing large f
2.3 Extended function argument syntax
14 Resultats, Darrera modificació:
en we talk about function arguments, we should recall the following facts: * some functions can be i... es for some parameters, so we do not have to pass all arguments as missing arguments, complete with def... ents in any order if we are assigning keywords to all argument values, otherwise positional ones are th... nt(3) print(1, 20, 10) print('--', '++') </code> All presented invocations of the **print()** function
2.8 Composition vs Inheritance - two ways to the same destination
11 Resultats, Darrera modificació:
this relation is a subclass class that inherits **all** methods and **all** properties of the base class, and allows a subclass to extend everything that ha... could be inherited in this “Vehicles” structure? All classes derived from Vehicles own properties and ... operty from the base class, then it is present in all subclasses. The same principle should apply to t
2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
9 Resultats, Darrera modificació:
d to a specific level of class hierarchy inherits all the traits (methods and attributes) defined insid... its. The new class inherits (and this is the key) all the already existing equipment, but is able to ad... ass TrackedVehicle(LandVehicle): pass</code> All the presented classes are empty for now, as we're... erited from both classes B and C. If you want to call the method info(), which part of the code would b
2.9 Inheriting properties from built-in classes
9 Resultats, Darrera modificació:
lt, your newly-created class has the advantage of all of the well-known functionalities inherited from ... s to the object. What have we not delivered? * All the remaining methods have remained unchanged, so... ions delivered above (validate the type and then call the corresponding superclass method). <code ; ou... ent if you wish; note: you have to teach the code all the lengths used in Europe) * (step 2) Move the
1.1 Classes, Instances, Attributes, Methods — introduction
8 Resultats, Darrera modificació:
Because an object is a very useful culmination of all the terms described above: * it is an independ... * methods: %%__init__%%, walk, quack — common to all objects so far. Examples: * To call a method, issue: drake.quack(); * To access an attribute, iss... the type of class, then type is returned; * in all other cases, it refers to the class that was used
1.2 Working with class and instance data – instance variables
8 Resultats, Darrera modificació:
instance variable of any object has no impact on all the remaining objects. Instance variables are com... nstance. Because it is owned by the class itself, all class variables are shared by all instances of the class. They will therefore generally have the same ... value unique to each class. When we iterate over all objects, we can examine the value of this variabl
3.1 Advanced techniques of creating and serving exceptions
8 Resultats, Darrera modificació:
iciently**. This is possible due to the fact that all potential exceptions have their unambiguous names... nguages): <code ; output> Traceback (most recent call last): File "exceptions#030.py", line 6, in <mo... ther exception occurred: Traceback (most recent call last): File "exceptions#030.py", line 8, in <mo... normally should be used as a last resort to catch all unhandled exceptions. It’s so wide because we don
5.1 Metaprogramming
6 Resultats, Darrera modificació:
* the type is responsible for calling the ''%%__call__%%'' method upon class instance creation; this m... ew__%%'' method has been defined. Its role is to call the ''%%__new__%%'' method of the parent class to... classes with a method (if missing) to ensure that all your classes are equipped with a method named 'gr... etaclass that is responsible for: * equipping all newly instantiated classes with time stamps, pers
2.7 Encapsulation
4 Resultats, Darrera modificació:
lass **to access** the values, and other objects call those methods to retrieve and modify the values w... nown as the author of Python, once said: "//We're all consenting adults here//" justifying the absence ... ants to read the level of liquid in our tank. We call such a read method **getter**. Pay attention to ... properties: properties are inherited, so you can call setters as if they were attributes. Examine the
4.2 Serialization of Python objects using the pickle module
4 Resultats, Darrera modificació:
nsmit it via a network. This byte stream contains all the information necessary to reconstruct the obje... ersisted: <code ; output> Traceback (most recent call last): File "main.py", line 4, in <module> ... r: def __init__(self): self.size = 'small' def get_size(self): return self.siz... receive: <code ; output> Traceback (most recent call last): File "main.py", line 4, in <module>
2.1 Python core syntax
3 Resultats, Darrera modificació:
d integers and we know what the result should be, all done by using the “+” operator, but on respective... 2) </code> <code ; output>Traceback (most recent call last): File "core#010.py", line 11, in pri... e attributes and methods of the object. When you call dir() on integer 10, you'll get: <code ; output>>
4.3 Making Python objects persistent using the shelve module
3 Resultats, Darrera modificació:
deserializing parties must abide by the order of all the elements placed into a file or database, or s... shed to the disk. To enforce an immediate flush, call the ''sync()'' method on your shelve object; * when you call the ''close()'' method on an shelve object, it al
2.5 Different faces of Python methods
2 Resultats, Darrera modificació:
_brand method'' is a class method, and expects a call with two parameters ('vin' and 'brand'). The firs... e the exception * After each watch is created, call class method to see if the counter variable was i
4.1 Shallow and deep copy operations
1 Resultats, Darrera modificació: