我有一门课和一些方法
class ThisClass:
def method1(self):
text1 = 'iloveyou'
return text1
def method2(self):
text2 = self.method1
print str(text2)
thisObj = ThisClass()
thisObj.method2
我得到的结果是
<bound method thisclass.method2 of <__main__.thisclass instance at 0x10042eb90>>
我怎么打印“我爱你”而不是那东西?
谢谢!
缺少方法调用的()。如果不使用()则打印方法对象的字符串表示形式,对于所有可调用项(包括自由函数)也是如此。
确保对所有方法调用都这样做(
self.method
1和thisObj.method2
)在
method2
中,可以调用函数而不是分配函数指针。相关问题 更多 >
编程相关推荐