-2
私はPythonの初心者です。以下はコードです。オブジェクトに指定された属性のエラーがPythonにありません
class simple:
def __init__(self, str):
print("inside the simple constructor")
self.s = str
# two methods:
def show(self):
print(self.s)
def showMsg(self, msg):
print(msg + ":", self.show())
if __name__ == "__main__":
# create an object:
x = simple("constructor argument")
x.show()
x.showMsg("A message")
私はそれを実行した後、私はそう
AttributeError: 'simple' object has no attribute 'show'
を持って、誰もがここで何が起こっているか知っているのですか? 'show'は属性ではありません。私の理解のために、それは方法でなければならない。誰がここで起こっていることを理解していますか?あなたの時間と注意に感謝します。
インデントはPythonでは必要です。インスタンスメソッドがクラス内にあることを確認してください。 – idjaw