来自类外部的python调用方法 [英] python call method from outside the class
本文介绍了来自类外部的python调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何在python中从位于类内部的外部调用方法?
how can I in python call method from outside which is situated inside the class?
class C():
def write():
print 'Hello worl'
我认为>>>x = C
和>>>x.write()
必须工作,但不能.
I thought that >>> x = C
and >>> x.write()
must work but it doesn't.
推荐答案
您是否需要在定义中加入自我?
Dont you need to have self in your definition?
class C(object):
def write(self):
print 'Hello world'
现在应该可以了,即
x = C()
x.write()
这篇关于来自类外部的python调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文