about __str__
Bruno Desthuilliers
bruno.42.desthuilliers at wtf.websiteburo.oops.com
Mon Sep 24 05:45:43 EDT 2007
Mikael Olofsson a écrit :
> 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.
Agreed. Well, at least until you want to access something that's not in
the instance's __dict__ !-)
More information about the Python-list
mailing list