Hello all! I have an application running under Python2.6 and the classes are set up with properties (in a Python2.4 style, though).
Everything seems to be working fine with SqlAlchemy (version 0.6.5, just in case) as it explains here: http://www.sqlalchemy.org/docs/orm/extensions/declarative.html#defining-synonyms The problem is that sometimes I want to get the properties of a class without knowing in advance the name or number of said properties. Before introducing SqlAlchemy, I had a little function that extracted them from the class (the __class__ attribute in an instance): def iter_properties_of_class(cls): retval = list() for varname in vars(cls): value = getattr(cls, varname) if isinstance(value, property): list.append(varname) return retval Now they're not instance of property anymore. I dug out a little and I found that what before were “properties” now are type: <class 'sqlalchemy.orm.attributes.propertyProxy'> So I thought... oh, ok... then I just have to check if they're instance of that propertyProxy class... And so I changed my “auxiliary” method to: import sqlalchemy [ . . . ] if isinstance(getattr(cls, varname), sqlalchemy.orm.attributes.propertyProxy): retval.append(varName) but I get this error: 'module' object has no attribute 'propertyProxy' I also tried with... if isinstance(getattr(cls, varname), sqlalchemy.orm.attributes.propertyProxy.propertyProxy) … getting the same error, or to import propertyProxy directly... from sqlalchemy.orm.attributes import propertyProxy … getting: ImportError: cannot import name propertyProxy So here's the question: Is there any way to get the properties of a class mapped with SqlAlchemy? Just in case, all my classes (at least for the moment) are implemented using the Declarative method. An small example could be my "User" class: ------------ User.py --------- class User(Base): """Represents a user""" __tablename__ = "users" _id = Column("id", Integer, primary_key=True) _userName = Column("user_name", String(50)) _password = Column("password", String(64)) def __init__(self): """Initialize object""" self._id = -1 self._userName = "" self._password = "" def setId(self, id): """Set id""" self._id = int(id) def getId(self): """Get id""" return self._id def setUserName(self, userName): """Set userName""" self._userName = userName def getUserName(self): """Get userName""" return self._userName def setPassword(self, password): """Set password""" m = hashlib.sha256() m.update(password) self._password = m.hexdigest() def getPassword(self): """Get password""" return self._password id = synonym('_id', descriptor=property(getId, setId)) userName = synonym('_userName', descriptor=property(getUserName, setUserName)) password = synonym('_password', descriptor=property(getPassword, setPassword)) --------------------- I'd like to know the best way to get a list() containing: ["id", "userName", "password"] Thank you in advance! -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.