Py学习  »  Python

python创建自定义魔术方法

Jasonca1 • 7 年前 • 2113 次点击  

在python中,如果我想创建一个对象,它在传递给特定函数时做了一些事情,我该怎么做呢? 例如:

import logging
class  TestObject:
    def __logging__(self):
        # It would check the calling function here and return something 
        # if it was a log function call from a logging class log function call
        return 'Some text'
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/40535
文章 [ 2 ]  |  最新文章 7 年前