擅长:python、mysql、java
<p>您尚未实例化该类。为了从你得到的东西中产生输出,请尝试以下操作:</p>
<pre><code>if __name__ == '__main__':
instance = MyClass()
</code></pre>
<p>--修订--</p>
<p>根据您重写的代码,您应该具有以下内容:</p>
<pre><code>class MyClass(object):
def __init__(self):
#myClassObject= MyClass() # Causes recursion error.
#myClassObject.greet() # You should not be accessing your instance method this way
self.greet()
def greet(self):
print("stackoverflow is the best !!!")
if __name__ == '__main__':
instance = MyClass()
</code></pre>
<p>你的例子似乎太复杂了。您最好检查一下Python中<a href="http://docs.python.org/2.7/tutorial/classes.html" rel="nofollow">Python 2.7</a>或<a href="http://docs.python.org/3.3/tutorial/classes.html" rel="nofollow">Python 3.3</a>的类用法。</p>