你需要做一些像:
class Person(object): #always inherit from object. It's just a good idea...
@staticmethod
def call_person():
print "hello person"
#Calling static methods works on classes as well as instances of that class
Person.call_person() #calling on class
p = Person()
p.call_person() #calling on instance of class
根据你想要做什么,类方法可能更合适:
class Person(object):
@classmethod
def call_person(cls):
print "hello person",cls
p = Person().call_person() #using classmethod on instance
Person.call_person() #using classmethod on class
这里的区别是,在第二个示例中,类本身作为方法的第一个参数传递(与实例是第一个参数的常规方法相反,或者不接收任何其他参数的静态方法)。
现在回答你的实际问题。我认为你没有找到你的方法,因为你把类Person放在一个模块Person.py中。
然后:
import Person #Person class is available as Person.Person