Cerca

Heus ací els resultats de la cerca.

2.9 Inheriting properties from built-in classes
26 Resultats, Darrera modificació:
we focus on the problem and not on type control. Look at the code presented in the editor pane. <cod... built-in dictionary, which will be equipped with logging mechanisms for details of writing and readin... super().__init__(*args, **kwargs) self.log = list() self.log_timestamp('MonitoredDict created') def __getitem__(self, key):
3.1 Advanced techniques of creating and serving exceptions
15 Resultats, Darrera modificació:
y to handle the problem in an elegant way. Let's look at typical try ... except statement. <code pyt... concepts in your applications. Once again, let's look at a typical try ... except statement. <code p... d when the import statement has trouble trying to load a module. The attributes are: * name – repres... riggers an additional exception. Should your code lose the information about the previous exception? O
4.2 Serialization of Python objects using the pickle module
15 Resultats, Darrera modificació:
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... idata.pckl', 'rb') as file_in: data1 = pickle.load(file_in) data2 = pickle.load(file_in) print(type(data1)) print(data1) print(type(data2)) print
4.1 Shallow and deep copy operations
14 Resultats, Darrera modificació:
nted in the right pane to see how the strings are located in the memory. <code python> a_string = '10... ying the original at the same time. Let's have a look at the following code. Its intention is to: *... independent copy of the ''a_list'' object should look like the code presented in the right pane. <co... alse </code> The graphical representation should look like the following: {{ :info:cursos:pue:python-
2.4 Decorators
7 Resultats, Darrera modificació:
* the measurement of execution time; * message logging; * thread synchronization; * code refact... _hello) decorated() </code> The whole code should look like the code presented in the right pane. Whe... this approach? Well … we could say … you should look at the following syntactic sugar: As you can s... _matter_function() </code> the call sequence will look like the following: * the outer_decorator is
2.6 Abstract classes
7 Resultats, Darrera modificació:
e module containing the ABC class instead of your local file. This could cause some confusion – why do... er, so device capabilities (resolution) should be low; * MFD2 – should be a medium-priced device a... on history, and the resolution is better than the lower-priced device; * MFD3 – should be a premiu... t__(self) Printer.__init__(self) def low(self): self.scanner_resolution = 100
5.1 Metaprogramming
6 Resultats, Darrera modificació:
ven implementing the properties protocol. It may look like syntactic sugar, because in many cases met... lasses redirect class instantiations to dedicated logic, contained in metaclasses. Metaclasses are app... e program advanced modules or frameworks, where a lot of precise automation must be provided. The typical use cases for metaclasses: * logging; * registering classes at creation time;
2.1 Python core syntax
5 Resultats, Darrera modificació:
o integers, or even two Person class objects – it looks for the magic method responsible for the calle... s blueprints) to perform the appropriate action. Look at the following simple code: <code python>numb... self+value. (...) </code> The names listed above look somehow familiar, so let's see the details deli... the documentation for the built-in integer type. Look at the last lines of the output – it contains i
2.2 Inheritance and polymorphism — Inheritance as a pillar of OOP
5 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** ... isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace... de ; output> 30 abcdef </code> By the way, if you look for a method that is used when you print a valu
1.2 Working with class and instance data – instance variables
4 Resultats, Darrera modificació:
the following way: objectdotvariable_name. Let's look at how the instance variable is created and acc... code that creates objects representing apples as long as both limitations are met. When any limitatio... ginary weight unit; Hint: Use a ''random.uniform(lower, upper)'' function to create a random number between the lower and upper float values. <code python> import
2.8 Composition vs Inheritance - two ways to the same destination
4 Resultats, Darrera modificació:
he top (the superclass) while its descendants are located below (the subclasses). What could be inher... s behavior. It’s worth mentioning that blocks are loosely coupled with the composite, and those blocks... to write some code to see how composition works. Look at the simple code presented in the editor pane... y_car.engine.start() </code> The “Car” class is loosely coupled with the “engine” component. It’s a
2.7 Encapsulation
3 Resultats, Darrera modificació:
deleting the encapsulated attribute. Let's have look at the code in the editor. <code python> class... a convenient way, without even knowing about the logic hidden behind it. So, whenever you'd like to c... it should not be possible to delete an account as long as the balance is not zero; * test your class
4.3 Making Python objects persistent using the shelve module
3 Resultats, Darrera modificació:
rack with shelves in the pantry is a correct one. Looks delicious, doesn’t it? Using shelve is quite ... elve module is backed by pickle, it isn’t safe to load a shelve from an untrusted source. As with pickle, loading a shelve can execute arbitrary code.
1.1 Classes, Instances, Attributes, Methods — introduction
2 Resultats, Darrera modificació:
e. The class is something virtual, it can contain lots of different details, and there is always one c... can be inherited from; * as a result, if you’re looking for the type of class, then type is returned
2.3 Extended function argument syntax
2 Resultats, Darrera modificació:
nctions ourselves? The answer is yes, but it may look strange at first glance: //%%*%%args and %%**%%... n a dictionary type parameter. Now if you take a look at the built-in print() function definition, it
2.5 Different faces of Python methods
2 Resultats, Darrera modificació: