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 overwrite the __class__.__dict__: class J(object): name = '' value = '' def __str__(self): vals = dict(self.__class__.__dict__) vals.update(self.__dict__) return 'name="%(name)s" value="%(value)s' % vals > What's wrong with the obvious version: [...] Oh, that looks nice and clean. I like it. I also found a recipe in the Python cookbook that works great for "dumping" objects: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/137951 (shortened: http://snipurl.com/hka7 ) Thanks! -Adam -- Adam Monsen http://adammonsen.com/
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4