about __str__

Mikael Olofsson mikael at isy.liu.se
Mon Sep 24 04:40:53 EDT 2007


Bruno Desthuilliers wrote:
> def __str__(self):
>     return "<%s:%s>" % (self.commiterID_, self.commits_)

I would write that in the following way:

def __str__(self):
    return "<%(commiterID_)s:%(commits_)s>" % self.__dict__

More explicit IMHO. And easier to maintain, especially if the string 
would contain several insertions.

/MiO



More information about the Python-list mailing list