类里的方法要不要加参数

class BookConfig():
list_display = ['title','price','nid','publish']
links_display=['title']
search_conditon = ['title','price']
def delete_action(self,qu):
print(qu)
print(123)
delete_action.desc='批量删除'

def init_action(self):
pass
init_action.desc='批量初始化'
actions=[delete_action,init_action]


book=BookConfig()

func=getattr(BookConfig,'delete_action')
print(func(book,'qunima'))
print(book.delete_action('qunima'))

当得到BookCongfig的方法时,只是一个方法,不知道是哪个对象要调用它,
print(func(book,'qunima'))所以要传self



如果是
func=getattr(book,'delete_action')
就不要传对象,因为已经把book传进去了,已经知道是哪个对象调用了,

就可以直接fun('去你妈')















posted @ 2018-07-26 09:39  赵伟航  阅读(522)  评论(0编辑  收藏  举报