Cerca

Heus ací els resultats de la cerca.

4.1 Shallow and deep copy operations
52 Resultats, Darrera modificació:
a variable, which you should treat as a label or name binding, is created, and this label refers to a d... <code python> import copy a_dict = { 'first name': 'James', 'last name': 'Bond', 'movies': ['Goldfinger (1964)', 'You Only Live Twice'] } b_... output** <code ; output> Source list of candies {'name': 'Lolly Pop', 'price': 0.4, 'weight': 133} {'nam
3.1 Advanced techniques of creating and serving exceptions
49 Resultats, Darrera modificació:
ort introduction to exceptions; * review of the named attributes of exception objects; * introductio... t all potential exceptions have their unambiguous names, so you can categorize them and react appropriat... a try... except block. == Advanced exceptions - named attributes Now it’s time to dive more deeply int... clause may specify a variable after the exception name. In this example it’s an ''e_variable''. This var
5.1 Metaprogramming
33 Resultats, Darrera modificació:
ent way than decorators: * decorators bind the names of decorated functions or classes to new callabl... familiar with some special attributes: * ''%%__name__%%'' – inherent for classes; contains the name of the class; * ''%%__class__%%'' – inherent for both... s dog = Dog() print('"dog" is an object of class named:', Dog.__name__) print() print('class "Dog" is a
2.4 Decorators
23 Resultats, Darrera modificació:
a new "decorating" function (or class), hence the name "decoration". This is done by passing the origina... int('We are about to call "{}"'.format(function.__name__)) return function </code> The last lines a... accepts an object as a parameter, displays a ''__name__'' attribute value of the parameter, and returns... ans that: * operations are performed on object names; * **this is the most important thing to remem
2.7 Encapsulation
12 Resultats, Darrera modificació:
to read the encapsulated attribute value; * the name of the designated method will be used as the name of the instance attribute corresponding to the encaps... that the method following the decorator gives the name (tank) to the attribute visible outside of the class. Moreover, we see that two other methods are named the same way, but as we are using specially craf
2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
9 Resultats, Darrera modificació:
inheritance is illustrated by a classical problem named the diamond problem, or even the deadly diamond of death. The name reflects the shape of the inheritance diagram — t... at the picture. There is the top-most superclass named A; there are two subclasses derived from A — B and C; and there is also the bottom-most subclass named D, derived from B and C (or C and B, as these tw
1.2 Working with class and instance data – instance variables
8 Resultats, Darrera modificació:
variable in the following way: objectdotvariable_name. Let's look at how the instance variable is crea... class variable, simply access it using the class name, and then provide the variable name. <code python> class Demo: class_var = 'shared variable' prin... creating an instance variable that holds the same name as the class variable. The following snippet show
2.8 Composition vs Inheritance - two ways to the same destination
4 Resultats, Darrera modificació:
You can achieve similar goals by using a concept named composition. This concept models another kind o... ty is to provide methods for both engine classes, named in the same way (here is the ''start()'' method)... build the composite should implement the methods named in the same manner to provide a common interface... ecific method, the inherited method with the same name will be called. Additionally, in the case of inhe
4.2 Serialization of Python objects using the pickle module
4 Resultats, Darrera modificació:
h built-in and user-defined) are pickled by their name reference, not by any value. This means that only the function name is pickled; neither the function’s code, nor any ... , are pickled. Similarly, classes are pickled by named reference, so the same restrictions in the unpic... s, the function or class must be available in the namespace of your code reading the pickle file. Other
4.3 Making Python objects persistent using the shelve module
4 Resultats, Darrera modificació:
s). <code python> new_shelve = shelve.open(shelve_name) print(new_shelve['USD']) new_shelve.close() </co... e right pane. <code python> import shelve shelve_name = 'first_shelve.shlv' my_shelve = shelve.open(shelve_name, flag='c') my_shelve['EUR'] = {'code':'Euro', 'sy... y_shelve.close() new_shelve = shelve.open(shelve_name) print(new_shelve['USD']) new_shelve.close() </c
2.1 Python core syntax
3 Resultats, Darrera modificació:
ted by design to handle specific operations. The name of each magic method is surrounded by double unde... /) | Return self+value. (...) </code> The names listed above look somehow familiar, so let's see... hon.org/3/reference/datamodel.html#special-method-names. What are some real life cases which could be i
2.3 Extended function argument syntax
3 Resultats, Darrera modificació:
n a short moment. These two special identifiers (named *args and %%**%%kwargs) should be put as the last two parameters in a function definition. Their names could be changed because it is just a convention to name them 'args' and 'kwargs', but it’s more important
2.5 Different faces of Python methods
3 Resultats, Darrera modificació:
. This is possible thanks to using ''self''. The name of the parameter ''self'' was chosen arbitrarily ... chosen arbitrarily (i.e., you can use a different name, but you must do it consistently). You can find ... The number could be fetched using a class method named ''get_number_of_watches_created''; * the class
2.6 Abstract classes
3 Resultats, Darrera modificació:
ions in order to call them by using common method names. Furthermore, a class which contains one or mor... ining Abstract Base Classes (ABC) and that module name is **abc**. The ABC allows you to mark classes a... uld cause some confusion – why does such a common name as “abc” conflict with my simple module “abc”? R
1.1 Classes, Instances, Attributes, Methods — introduction
2 Resultats, Darrera modificació:
/code> In the code above, we have defined a class named Duck, consisting of some functionalities and att... cribing the type/kind of any object; * it’s the name of a very handy Python function that returns the
2.9 Inheriting properties from built-in classes
1 Resultats, Darrera modificació: