On Thu, Sep 20, 2007 at 08:32:01PM -0000, shadowfox wrote:
> 
> Neat, but it only replaces the TreeBark.__dict__
> 
> Do you have another short hand to replace the ugly
> self.__dict__.get('_SO_val_%s' % a) ?
> 
> To be less cryptic, the idea is to get the actual value of the said
> column in a class instance.
> 
> On Sep 20, 12:54 pm, Jason Chu <[EMAIL PROTECTED]> wrote:
> > > class TreeBark(SQLObject):
> > >     property1 = StringCol(length=150, varchar=True,title="Main Picture
> > > URL")
> > >     property2 = StringCol(length=100,varchar=True,title="Title or
> > > Short Description",alternateID=True,notNone=True)
> >
> > >     def gimmeDict(self):
> > >         d = TreeBark.__dict__
> > >         props = dict()
> > >         for a in d:
> > >             if type(d[a]) == property:
> > >                 props[a] = self.__dict__.get('_SO_val_%s' % a)
> >
> > >         props['id'] = self.id
> > >         return props
> >
> > I usually find it much better to read TreeBark.sqlmeta.columnList than
> > __dict__.  You can even figure out what type of column it is from there.
> >
> > Jason

props = dict()
for column in self.sqlmeta.columnList:
    props[column] = getattr(self, column)

# I'm not sure if 'id' is in that columnList.

Jason

Attachment: pgpAxe1A983VS.pgp
Description: PGP signature

Reply via email to