在下面的代码中,有人能告诉我,在标记为#whereami
(第3行)的行中,我如何识别我现在在类Person中,而不是在实例化的程序员对象中。你知道吗
理想情况下,我想要一个类/类型对象,但如果不能返回,类名“Person”就可以了。你知道吗
class Person(object):
def opinion(self):
#whereami
print "Time for a cup of tea"
class Programmer(Person):
def opinion(self):
super(Programmer, self).opinion()
print "There is no spoon"
if '__name__' == '__main__':
programmer = Programmer()
programmer.opinion()
使用
请参见下面使用Python3.2的示例
结果
可以看出第一个结果是由“Person”类调用的。你知道吗
尝试插入以下行
className变量将当前类名的值作为字符串
相关问题 更多 >
编程相关推荐