組み込み属性はいつどのように初期化されますか?
__doc__
、__name__
(私はこれについて知っていると思います:))、、__class__
など__setattr__
。
docstringに関する他の質問では、回答の1つに、docstringは単なる単純な文字列であり、を試してみたところ、'
すべて機能したとのことでした。しかし、文字列値が割り当てられた変数を使用し、その変数をdocstringの代わりに配置すると、機能しません。そのため、属性はいつ初期化されるのか疑問に思い始めました。"
"""
__doc__
編集:これは私が通訳で試したものです(はい、これはクレイジーで、私は奇妙です:D)
doc_str = "Says Hello world"
class HelloWorld():
def say():
doc_str
print("Hello world !")
h_w = HelloWorld()
h_w.say.__doc__
class AnotherHelloWorld():
def __init__(self, doc_str="Says HELLO WORLD"):
self.doc_str = doc_str
def say(self):
self.doc_str
print("HELLO WORLD !")
a_h_w = AnotherHelloWorld("Scream... HELLO WORLD!")
a_h_w.say.__doc__
class YetAnotherHelloWorld():
def __init__(self, doc_str="Still does't say HELLO WORLD :( "):
self.doc_str = doc_str
def say(self):
"%s"%self.doc_str
print("HELLO WORLD .. Again!")