Re: [SQLObject] exporting to tab-delimited rows
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Jeff B. <jb...@ru...> - 2005-10-13 13:07:20
|
Oleg Broytmann wrote: > On Thu, Oct 13, 2005 at 07:34:41AM -0500, Jeff Bauer wrote: <snip> >> def export(cls): >> list = [] >> columns = ['id'] >> for col in cls.sqlmeta.columnList: >> columns.append(col.name) >> list.append('\t'.join(columns)) >> for row in cls.select(): >> data = [] >> for c in columns: >> data.append(str(getattr(row, c))) >> list.append('\t'.join(data)) >> return list >> >> export = classmethod(export) >> >>Is this reasonable, or is there a better way to >>achieve similar results? Thanks. > > > Looks good. Few notes: > > 1. Both cls.select() and list.append() will eat up memory. Don't do this on > a big table. For larger tables then, you'd suggest doing raw SQL calls to the database? > 2. Not all objects can be converted by str() - UnicodeCol, for example. Unicode? We don't need no stinkin' Unicode. <wink> Point noted. > 3. Don't forget to escape \t in your data; or make sure there are no tabs. Yes, not to mention embedded newlines. Thanks. |