> Thanks. I'll take your code, that's great. > But I found the code which Jonathan Ellis supplied shows two many things including mapper, etc. So I change it and the new version is:
def assign_class(table, **kwargs): import new import locale encoding = locale.getdefaultlocale()[1] klass = new.classobj('Class_' + table.name.capitalize(), (object,), {}) def __init__(self, **kwargs): for key, value in kwargs.items(): self.__dict__[key] = value def __repr__(self): s = [] for k in self.__class__.c.keys(): value = getattr(self, k, '') if isinstance(value, unicode): value = value.encode(encoding) else: value = str(value) s.append("%s=%s" % (k, value)) return '%s(%s)' % (self.__class__.__name__, ','.join(s)) klass.__init__ = __init__ klass.__repr__ = __repr__ klass.table = table assign_mapper(klass, table, **kwargs) return klass I also deal with encoding in there. But in some flatforms, may be getdefaultlocale() will return empty tuple. -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit ------------------------------------------------------- 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_idv37&alloc_id865&op=click _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users