簡體   English   中英

在構造函數調用中初始化Python靜態類屬性

[英]Initializing Python static class attributes in the constructor call

在某些Google 文檔中,有以下代碼(為清楚起見而縮寫)。 Note類已定義,然后在構造函數調用中使用參數實例化。 我不知道可以用這種方式初始化屬性。 這是本機Python功能還是Message超類中正在發生的某些魔術?

from protorpc import messages

class Note(messages.Message):

    text = messages.StringField(1, required=True)

# Import the standard time Python library to handle the timestamp.

note_instance = Note(text = u'Hello guestbook!')

它不符合您的思維方式。 Note類從Message繼承。 Message (或它繼承的其他類)在其__init__()方法中具有代碼來執行此操作。 沒有魔術。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM