On Dec 20, 2010, at 7:30 PM, Hector Blanco wrote: > 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?
I'd look at the object to see if it has a __get__() method, since that's what defines a "descriptor" in Python, not just isinstance(x, property). duck typing -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
