1. 程式人生 > 實用技巧 >ES叢集安裝

ES叢集安裝

1.Python直譯器對於class的釋義

A class definition defines a class object (see section The standard
type hierarchy):

   classdef    ::= [decorators] "class" classname [inheritance] ":" suite
   inheritance ::= "(" [argument_list] ")"
   classname   ::= identifier

A class definition is an executable statement.  The inheritance list
usually gives a list 
of base classes (see Metaclasses for more advanced uses), so each item in the list should evaluate to a class object which allows subclassing. Classes without an inheritance list inherit, by default, from the base class "object"; hence, class Foo: pass is equivalent to class Foo(object
): pass The class’s suite is then executed in a new execution frame (see Naming and binding), using a newly created local namespace and the original global namespace. (Usually, the suite contains mostly function definitions.) When the class’s suite finishes execution, its execution frame
is discarded but its local namespace is saved. [3] A class object is then created using the inheritance list for the base classes and the saved local namespace for the attribute dictionary. The class name is bound to this class object in the original local namespace. The order in which attributes are defined in the class body is preserved in the new class’s "__dict__". Note that this is reliable only right after the class is created and only for classes that were defined using the definition syntax. Class creation can be customized heavily using metaclasses. Classes can also be decorated: just like when decorating functions, @f1(arg) @f2 class Foo: pass is roughly equivalent to class Foo: pass Foo = f1(arg)(f2(Foo)) The evaluation rules for the decorator expressions are the same as for function decorators. The result is then bound to the class name. **Programmer’s note:** Variables defined in the class definition are class attributes; they are shared by instances. Instance attributes can be set in a method with "self.name = value". Both class and instance attributes are accessible through the notation “"self.name"”, and an instance attribute hides a class attribute with the same name when accessed in this way. Class attributes can be used as defaults for instance attributes, but using mutable values there can lead to unexpected results. Descriptors can be used to create instance variables with different implementation details. See also: **PEP 3115** - Metaclasses in Python 3000 The proposal that changed the declaration of metaclasses to the current syntax, and the semantics for how classes with metaclasses are constructed. **PEP 3129** - Class Decorators The proposal that added class decorators. Function and method decorators were introduced in **PEP 318**. Related help topics: CLASSES, SPECIALMETHODS
class 原文
類定義定義了一個類物件(參見標準部分)

型別層次結構):



classdef::= [decorator] "class" classname[繼承]":" suite

繼承::= "(" [argument_list] ")"

類名::=識別符號



類定義是一個可執行語句。繼承列表

通常給出基類的列表(更多資訊請參閱元類)

所以列表中的每一項都應該被評估為一個類

物件,該物件允許子類化。沒有繼承列表的類

預設情況下繼承基類“object”;因此,



類Foo:

通過



相當於



類Foo(物件):

通過



然後類的套件在一個新的執行框架中執行(參見

),使用新建立的本地名稱空間和

原來的全域性名稱空間。(通常,套件包含了大部分

函式定義)。當類的套件完成執行時,它的

執行框架被丟棄,但其本地名稱空間被儲存。[3]一個

然後使用基類的繼承列表建立類物件

類和儲存的屬性字典的本地名稱空間。

類名在原始本地繫結到這個類物件

名稱空間。



類主體中定義屬性的順序為

保留在新類別的“剩餘書寫__”中。注意,這是可靠的

僅在類建立之後,且僅適用於已建立的類

使用定義語法定義。



可以使用元類大量定製類的建立。



類也可以被裝飾:就像裝飾函式一樣,



@f1 (arg)

@f2

類Foo:通過



大致相當於



類Foo:通過

Foo = f1 (arg) (f2 (Foo))



裝飾器表示式的計算規則與for相同

函式修飾符。然後將結果繫結到類名。



**程式設計師注意:**在類定義中定義的變數是

類屬性;它們由例項共享。例項屬性

可以在方法中設定"self。name = value"。類和

例項屬性可以通過“self。name”符號訪問,

例項屬性隱藏具有相同名稱的類屬性

以這種方式訪問時。類屬性可以作為預設值使用

但是使用可變值可能導致

意想不到的結果。描述符可用於建立例項

具有不同實現細節的變數。



參見:



**PEP 3115** - Python 3000中的元類

將元類的宣告更改為

當前的語法,和如何類的語義

元類的構造。



**PEP 3129** -類裝飾器

新增類裝飾器的建議。函式和方法

decorator是在**PEP 318**中引入的。



相關幫助主題:類、特殊方法
class 譯文 湊合看