Re: using % operator to print possibly unitialized data attributes

2005-09-09 Thread François Pinard
[Adam Monsen] > The following code uses the % operator to print possibly unitialized > data attributes: > 8< > class J: > name = '' > value = '' > def __str__(self): > vals = self.__class__.__dict__ > vals.update(self.__di

Re: using % operator to print possibly unitialized data attributes

2005-09-09 Thread Adam Monsen
Leif K-Brooks wrote: > This will update the class's attributes with instance attributes > when str() is called, which probably isn't what you want. [...] Yikes, you're right! Well, I figured out a modification to my original __str__ code that works for old and new-style classes which doesn't overw

Re: using % operator to print possibly unitialized data attributes

2005-09-09 Thread Leif K-Brooks
Adam Monsen wrote: > class J: > name = '' > value = '' > def __str__(self): > vals = self.__class__.__dict__ > vals.update(self.__dict__) > return 'name="%(name)s" value="%(value)s' % vals This will update the class's attributes with instance attributes when str

using % operator to print possibly unitialized data attributes

2005-09-09 Thread Adam Monsen
The following code uses the % operator to print possibly unitialized data attributes: 8< class J: name = '' value = '' def __str__(self): vals = self.__class__.__dict__ vals.update(self.__dict__) return 'name="%(nam