I know that I can write code like:
class A : def __getattr__ (self, name) : return name
to catch access to undefined attributes for an instance of the class, therefore:
A().ATTR == 'ATTR'
- it's true. But is there a way to do this for the class itself? What I would like to have is to have the following two lines and work, and be distinguishable (i.e. there are different magic methods, or the magic method can determine how it was called)
a = A().ATTR b = A.ATTR
I suspect there is no answer, but maybe there is some kind of deep python ju-ju?
Change The actual problem is expanding the user library of the active record in a backward compatible way. ORM code supports code in lines
ar = AR_people() ar.find() name = ar.name
to access tables where name can be mapped to a column name that is different, for example. pe_name . We want to write something like
ar.filter(AR_people.age >= 21)
and in the end
pe_age >= 21
(like other ORM libraries), so AR_people.age must return an instance of a class that implements __ge__ , etc., to do the magic of conversion.
source share