[Tutor] Help with class.self variables

Kent Johnson kent37 at tds.net
Wed May 14 14:16:33 CEST 2008


On Wed, May 14, 2008 at 3:45 AM, Mark <mobiledreamers at gmail.com> wrote:

>  i want to set the keys of the user row as the keys of User self
>  but i m not sure how to do it
>
>          for i in self._user.keys():
>              self[i]=self._user[i]

Should be
  setattr(self, i, self._user[i])

>  You can do something like
>
>  self.update(_user)

Should be
  self.__dict__.update(self._user)

You should probably consider an existing object-relation mapper such
as SQLAlchemy, SQLObject or Django ORM rather than rolling your own.

Kent


More information about the Tutor mailing list