Cerca
Heus ací els resultats de la cerca.
Resultats de text complet:
- 1.2 Working with class and instance data – instance variables
- - we instantiate the class twice, each time passing a different value to be stored inside the object... Moreover, it lists the contents of each object, using the built-in __dict__ property that is present f... get access to a class variable, simply access it using the class name, and then provide the variable na... en you try to set a value for the class variable using the object (a variable referring to the object o
- 2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
- f building a new class, not from scratch, but by using an already defined repertoire of traits. The new... cle** classes. == Inheritance and polymorphism — Single inheritance vs. multiple inheritance There are no obstacles to using multiple inheritance in Python. You can derive a... nheritance should be used with more prudence than single inheritance because: * a single inheritance
- 2.5 Different faces of Python methods
- e indicated instance. This is possible thanks to using ''self''. The name of the parameter ''self'' wa... s has been signaled to the Python interpreter by using an appropriate decorator. Additionally, the meth... The first parameter is used to create an object using the standard ''%%__init__%%'' method. In accord... __init__%%'' method, among other things) is done using ''cls(vin)''. Then the class method performs an
- 2.8 Composition vs Inheritance - two ways to the same destination
- ways to the same destination So far we've been using and following the inheritance concept when model... ptable objects. You can achieve similar goals by using a concept named composition. This concept model... cific engine. Composition is the process of composing an object using other different objects. The objects used in the composition deliver a set of desired
- 5.1 Metaprogramming
- oof, woof </code> This way of creating classes, using the type function, is substantial for Python's way of creating classes using the ''class'' instruction: * after the ''clas... sible for completing classes with a method (if missing) to ensure that all your classes are equipped wi... S')} ({self.instantiation_time})") class MetaClassInstantation(type): instantiated = list() de
- 2.7 Encapsulation
- ** ) while your appliance is washing it ( **processing** ). You have a set of controls ( **methods** ) ... window). So, while the washing machine is processing your laundry, you are not able to directly acces... er methods are named the same way, but as we are using specially crafted decorators to distinguish them... esignated methods by allowing the other code accessing the 'level' attribute. We can also react to oper
- 2.1 Python core syntax
- = 2.1 Python core syntax So far we have been using Python core operations that allow us to operate on s... ts. It’s natural for us to formulate expressions using algebraic symbols representing operators, or to ... d we know what the result should be, all done by using the “+” operator, but on respective data types. ... ent** data types, when operations are formulated using **the same** operators or instructions, or even
- 2.4 Decorators
- , hence the name "decoration". This is done by passing the original function (i.e., the **decorated** f... ld reference an object (own_function) in its enclosing scope thanks to the closure. == Decorators can ... passed * ''warehouse_decorator'' – which wraps single items into different materials. We’ve also cr... ython> # import module responsible for time processing from datetime import datetime # get current tim
- 4.1 Shallow and deep copy operations
- llow and deep copy operations == Copying objects using shallow and deep operations In this module, you’... Python code that performs any kind of data processing without making use of variables. As variables ar... copy of ''a_list'', (not just a copy reference). Using ''[:]'', which is an array slice syntax, we get ... on to copy any type object, so that in that case using a ''copy()'' function is the smart way to accomp
- 2.9 Inheriting properties from built-in classes
- hat logs activities. But don’t worry, we’re not losing anything from the parent dictionary class, becau... announcement; * line 11: start the actual processing; * line 12: move the four initial characters t... his is a good example of making use of the subclassing feature to enrich your code with an important se... tuple, dictionary, and many others; * by subclassing the built-ins, you can easily adapt generics to
- 3.1 Advanced techniques of creating and serving exceptions
- object. Both of these activities are called **raising an exception**. We can say that Python always ra... cepts and get familiar with the possible ways of using those concepts in your applications. Once again... ect in a handy and consistent way for later processing like logging, etc. Look at the following code a... ack. Pay attention to the fact that we are not raising any exception explicitly with a raise statement,
- 4.2 Serialization of Python objects using the pickle module
- = 4.2 Serialization of Python objects using the pickle module In this section, you will learn how to pe... r considered saving the output of your data processing for later use? The simplest way to persist outc... zation**. Python objects can also be serialized using a module called 'pickle', and using this module, you can 'pickle' your Python objects for later use.
- 4.3 Making Python objects persistent using the shelve module
- = 4.3 Making Python objects persistent using the shelve module == Serialization of Python objects using the shelve module As you remember, the pickle module is used for serializing objects as a single byte stream. Both serializing and deserializin... is a correct one. Looks delicious, doesn’t it? Using shelve is quite easy and intuitive. First, let'
- 2.3 Extended function argument syntax
- rs, so we do not have to pass all arguments as missing arguments, complete with defaults; parameters wi... uments and keyword arguments. So far we've been using a few such functions, but we haven't focused muc
- 1.1 Classes, Instances, Attributes, Methods — introduction
- OP, and even the mouse cursor image is displayed using an application created with OOP. The same applie