Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#122 Feature request: dict conversion

closed-rejected
nobody
General (125)
5
2005-10-27
2005-10-26
No

I know this could be odd, and probably you won't add
it, but I think I could be useful to easyly convert an
sqlobject to a dictionary. Adding this 3 methods to
SQLObject does the trick:

class SQLObject(object):
# ...
def keys(self):
return self.sqlmeta.columns.keys()

def __len__(self):
return len(self.sqlmeta.columns)

def __getitem__(self, key):
return getattr(self, key)

Now you can do something like

class Obj(SQLObject):
attr1 = StringCol(default='Test')
attr2 = IntCol(default=1)

o = Obj()
print dict(o)
{ 'attr1': 'Test', 'attr2': 1 }

Discussion

  • Ian Bicking
    Ian Bicking
    2005-10-27

    • status: open --> closed-rejected
     
  • Ian Bicking
    Ian Bicking
    2005-10-27

    Logged In: YES
    user_id=210337

    I've added a .sqlmeta.asDict() method for SQLObject
    instances. While a method to produce a "live"
    dictionary-like object would also be acceptable, SQLObject
    instances won't develop any direct dictionary-like methods.

     
  • Logged In: YES
    user_id=240225

    Fair enough =)