On Sep 20, 8:38 pm, Peng Yu <pengyu...@gmail.com> wrote:
> Hi,
>
> I have the following code. I want to change the function body of
> __repr__ to something like
>
>     return 'In %s::%s' % ($class_name, $function_name)
>
> I'm wondering what I should write for $class_name and $function_name in 
> python.
>
> Regards,
> Peng
>
> class A:
>   def __init__(self):
>     pass
>
>   def __repr__(self):
>     return 'In A::__repr__'
>
> a = A()
> print a

Using decorator:
----------------

def echo(func):
    def _echo(self, *args, **kw):
        return "In %s.%s" % (self.__class__.__name__, func.func_name)

    return _echo

class A:

    @echo
    def __repr__(self):
        pass

a = A()
print a

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to