class - How does this use of Python's __metaclass__ work? -
I got a presentation about generator and functional programming. I stumbled on __ metaCLASS__
-
Why the argument of
genuine
andfloat
Accounting? Usually there isbase
, but is it necessary to type inreal
andfloat
? -
What does
__bastmethods __
do? I can not find it in the general list of special methods. -
Does the author enrich his own
accounting class by using those two methods of classes, with the ways of other sections, loops?
Why does
account (getattr (float, meth) (* args, ** kwargs))
The result is not in the infinite loop? Unlike the second edition, what happens here? First of all, it is a fraction that is relevant to my question:class accounting ( Real, float): def __metaclass __ (name, base, body): for the method in real .__ abstractmethods__: If the method is not in the body: body [method] = (Lambda meth: lambda * args, * * quarwiz: method For the method in ('__ne __', '__najiro_',)) (method (float, meth) (* args, ** quargas)) (method): If the method is not in the body: body [method] = (Lambda Eith: lambda * algés, ** quarz: gator (float, meth) (* args, ** quorz)) (method) react real .__ metaclass __ (name, bass, body) __new__ = float .__ new__
: in real .__ abstractmethods__ For the method: If the method is not in the body: (for method in '__ne __', '__ nozerza') [method] = (Lambda meth: lambda * algés, ** quarj: ac Accounting (Gator (float, meth) (* ARG, ** quarj))): (If method is not in the body: body [method] = (Lambda meth: lambda * algés, ** quarrels: gator (Float (Math, FMT): Returns {1: '% s'% Float .__ format __ (Self, FMT), 0: '% s'% float .__ format __ (self, fmt): __new__ = float .__ new__def __format__ (self, fmt) (' 0 ',' - '), -1:' (% s ) '% Float .__ format __ (self, FMT)} [C Mpi (Self, 0)]
The code used here:
template = "{field: & lt; {Align}} {Benefits: & gt; 14, .0f} '. Format def production (market, write = print area (area) = (field = area, profit = gain, align = align) type (line) output () {field: accounting (p for field area, markets.items ()} )
Output:
Central America (-675,140) US (-2,724,620) Antarctica - Asia (-3,614,396) UK (-2,380,001) European Answer: Answer: Answer: Union 771,665 CEMEA 3,480,172 Code> Reason for Real .__bstractmethods__: if the method Is not in body: body [method] = (lambda meth: lambda * args, ** kwargs: accounting (getattr (float, meth)) (* args, ** kwargs)) (method)
numbers.Real is an abstract class (i.e. you can not prove an example of this, but you can use it as a sub-class. Real class has a special frozenet which is __bittalmuptens __ is called
, which lists all the methods that expect to define the actual class. :
In the Interactive Interpreter: Import Real Real from Numbers <__> , '' ___ ',' ___ ',' ___ ',', '__le__', 'metaclass') is a solid definition for each of these methods
I will accept that I have nested lambda definition I do not completely mess up.
Comments
Post a Comment