On Dec 30, 2005, at 4:26 PM, Jonathan Ellis wrote:
In my own code I like to return something like 'Foo(a1=v1, a2=v2)'
which with an appropriate constructor follows the guideline that
__repr__ should be something you can turn back into the object
instance. Something like
L = ['%s=%s' % (a, repr(getattr(self, a))) for a in dir(self) if
not callable(getattr(self, a)) and not a.startswith('_')]
return '%s(%s)' % (self.__class__.__name__, ','.join(L))
well yeah, thats assuming I am absolutely consistent in my attribute
assignment and naming schemes :)...in reality i have a lot of public
attributes that arent in the constructor, alot of *args that are
consumed, etc., so yeah the __repr__ thing is possible but would have
to be hand-coded in many cases, and sometimes it will mean some
values that are normally consumed would be kept in memory. we should
definitely add a ticket for this, since it will be a long process to
get __repr__'s all around like that. I also do a lot of caching of
expensive objects based on their "constructor", so the __repr__
functionality should be rolled into that as well where needed.
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users