471,351 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,351 software developers and data experts.

__getattr__ and static vs. instantiated


Let's say I have:

class Persistable(object):

__attrs__ = {}

def __getattr__(self, name):
if name in self.__attrs__:
return self.__attrs__[name]['value']
return Object.__getattr__(self, name)

def __setattr__(self, name, value):
if name in self.__attrs__:
self.__attrs__[name]['value'] = value
Object.__setattr__(self, name, value)

And the I have:

class Person(Persistable):

__storm_table__ = 'person'

id = Int(primary=True)

__attrs__ = {
'name': {
'lang': 'en',
'value': Unicode(),

def __init__(self):
self.id = int(random.random() * 1000)

I can do this:

person = Person()
person.name = 'Jane Smith'

But I cannot do:

Person.name = 'Jane Smith'

or use Person.name in a Storm query like:

Person.name == 'Jane Smith'

__getattr__ is only called when using an instantiated class, and
never, it seems, in a static case. Why? How do I work around this?


P.S. This is Python 2.5 on Ubuntu Feisty x86.

Sep 11 '07 #1
0 851

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Holger Joukl | last post: by
7 posts views Thread by Drew McCormack | last post: by
4 posts views Thread by fred | last post: by
25 posts views Thread by Sahil Malik [MVP] | last post: by
5 posts views Thread by Fredp | last post: by
7 posts views Thread by James Crosswell | last post: by
4 posts views Thread by Enrico | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.