magic_repr

magic_repr.make_repr(*args, **kwargs)[source]

Returns __repr__ method which returns ASCII representaion of the object with given fields.

Without arguments, make_repr generates a method which outputs all object’s non-protected (non-undercored) arguments which are not callables.

Accepts *args, which should be a names of object’s attributes to be included in the output:

__repr__ = make_repr('foo', 'bar')

If you want to generate attribute’s content on the fly, then you should use keyword arguments and pass a callable of one argument:

__repr__ = make_repr(foo=lambda obj: obj.blah + 100500)