Cerca
Heus ací els resultats de la cerca.
Resultats de text complet:
- 4.2 Serialization of Python objects using the pickle module
- Remember to run the code locally. <code python> import pickle a_dict = dict() a_dict['EUR'] = {'code':... ile_out) </code> The code starts with the import statement responsible for loading the pickle module: <code python> import pickle </code> Later you can see that the file ... he file opened for writing in binary mode. It’s important to open the file in binary mode as we are dum
- 2.6 Abstract classes
- hy do we want to use abstract classes? The very important reason is: we want our code to be polymorphic... igning a music player application, intended to support multiple file formats. Some of the formats are k... concrete classes for each format you'd like to support. Whenever new format specifications become avail... ayer code, you’ll just have to deliver a class supporting the new file format, fulfilling the contract
- 2.4 Decorators
- rformed on object names; * **this is the most important thing to remember**: the name of the simple_f... ntroduces this syntax, which appears to be very important and useful to developers. That is why decorat... d. Decorators, which should be universal, must support any function, regardless of the number and type ... e object (function, method or class). The most important thing to remember is the order in which the d
- 3.1 Advanced techniques of creating and serving exceptions
- t raises an exception, and that is why it is so important to know how to deal with exceptions. Python ... information about the exception itself. The ''ImportError'' exception – raised when the import statement has trouble trying to load a module. The attribut... the name of the module that was attempted to be imported; * path – represents the path to any file wh
- 4.1 Shallow and deep copy operations
- ode presented in the right pane. <code python> import copy print("Let's make a deep copy") a_list = [... a million three-element tuples). <code python> import copy import time a_list = [(1,2,3) for x in range(1_000_000)] print('Single reference copy') time_s... hat safely copies the dictionary. <code python> import copy a_dict = { 'first name': 'James',
- 2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
- ssible pitfalls - MRO inconsistency **MRO** can report definition inconsistencies when a subtle change ... turned on') class Radio(Device): pass class PortableRadio(Device): def turn_on(self): print('PortableRadio type object was turned on') class TvSe... as turned on') device = Device() radio = Radio() portableRadio = PortableRadio() tvset = TvSet() for
- 5.1 Metaprogramming
- .png }} To extend the above observations, it’s important to add: * ''type'' is a class that generat... ore we start creating our own metaclasses, it’s important to understand some more details regarding cla... it’s time to implement our own metaclass. It’s important to remember that metaclasses are classes that... by your metaclass. === resposta <code python> import time import datetime def get_instantiation_time
- 4.3 Making Python objects persistent using the shelve module
- elve is quite easy and intuitive. First, let's import the appropriate module and create an object representing a file-based database: <code python> import shelve my_shelve = shelve.open('first_shelve.shl... e is presented in the right pane. <code python> import shelve shelve_name = 'first_shelve.shlv' my_sh... ce additionally that some files are created to support the database. Don’t try to alter those files wit
- 1.1 Classes, Instances, Attributes, Methods — introduction
- y beginning of computer programming. This very important approach is present in most computer applicat... rting to discuss more advanced OOP topics, it’s important to remember that in Python everything is an o... arameters, just like functions. This is a very important fact to remember: methods are called on behal
- 2.9 Inheriting properties from built-in classes
- of our dictionary. <code python> from datetime import datetime class MonitoredDict(dict): def __... pets, we get the following code: <code python> import random class IBANValidationError(Exception): ... subclassing feature to enrich your code with an important set of syntax and semantic checks. To test t
- 2.1 Python core syntax
- , line 11, in print(p1 + p2) TypeError: unsupported operand type(s) for +: 'Person' and 'Person'</... implementation prepared in the previous lab to support the addition and subtraction of integers to time
- 2.7 Encapsulation
- rols access to the attributes, and what is most important –consumer implementation does not have to be ... tor **@property**. This decorator plays a very important role: * it designates a method which will b
- 2.8 Composition vs Inheritance - two ways to the same destination
- Inheritance is a great concept, one of the most important foundations of object-oriented programming th... oose which domain-specific objects should be incorporated into your ultimate object. It's like arming y
- 1.2 Working with class and instance data – instance variables
- he lower and upper float values. <code python> import random class Pomes: total_w = 0 total_i
- 2.3 Extended function argument syntax
- to name them 'args' and 'kwargs', but it’s more important to sustain the order of the parameters and le