← Back to team overview

launchpad-dev team mailing list archive

Re: Give your models some repr love!

 

On 12 February 2010 03:51, Barry Warsaw <barry@xxxxxxxxxxxxx> wrote:
> It's easy to do, too.  E.g. I have a branch hopefully landing soon that adds
> this to class Language:
>
>    def __repr__(self):
>        return '<Language: %s>' % self.displayname
>
> A word of warning though: adding a repr to existing classes can break doctests
> far from the models you're modifying, so land such branches through ec2.

My normal practice is to use self.__class__.__name__ to avoid
confusion if it's later subclassed...


-- 
Martin <http://launchpad.net/~mbp/>



References