On Jan 5, 2006, at 10:57 PM, Jonathan Ellis wrote:
Looking good. I prefer the generic repr that I posted earlier,
though.
def __repr__(self):
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))
I suppose you could split that genexp into multiple lines if you
like, though. :)
Michael, my first reaction when reading the docs was to write a
function like this, too. I ended up deciding that I was probably
going to want to customize my classes more than would be convenient
with this, so I didn't, but for quick and dirty, maybe something
like this would be useful.
-J
its on my TODO list to get the above __repr__ in there at least on
the base classes, and probably write a customized one for the more
elaborate objects that need it (and also try to make the more
elaborate objects more compatible with the generic __repr__, if
possible...thats where the task starts to loom larger....)
also I have class_ all over the place, it has usually seemed less
annoying to me than using 'klass' which I have seen here and there.
but I suck at conventions....what do you think ?
-------------------------------------------------------
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