1、将Python中的一个类的方法设为静态的(即通过类名就可以调用),只需在方法名前加上“@staticmethod”
注意:使用了静态方法,则不能再使用self
class PersonManager(object):
@staticmethod
def saveOrUpdatePerson(person):
'''保存、更新一个联系人'''
name = person.name
self.personStore[name] = person
Util.Util.objectToFile(self.personStore, self.filepath)
注意:使用了静态方法,则不能再使用self