473,394 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

__getattr__ and static vs. instantiated

Hi,

Let's say I have:

class Persistable(object):

__attrs__ = {}

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

def __setattr__(self, name, value):
if name in self.__attrs__:
self.__attrs__[name]['value'] = value
else:
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?
Thanks.

-Tom

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

Sep 11 '07 #1
0 911

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Holger Joukl | last post by:
Hi there, please excuse my rather lengthy post. With introduction of the new style classes, something seems to have changed for __getattr__ hooks, even for classic classes: getattr.py: class...
7
by: Drew McCormack | last post by:
I have a C++ template class which contains a static variable whose construction registers the class with a map. Something like this: template <typename T> class M { static Registrar<M>...
4
by: fred | last post by:
Hi, can someone please explain to me how a static member of a class works. For example if I have: public Class1 public static Class2 myClass2 = new Class2; public static Int16 thisValue = 200;...
4
by: TS | last post by:
I am trying to add an event handler for a static variable of a class and i can't figure out how to do so since the class is never instantiated. The wmp variable gets instantiated when my code...
25
by: Sahil Malik [MVP] | last post by:
So here's a rather simple question. Say in an ASP.NET application, I wish to share common constants as static variables in global.asax (I know there's web.config bla bla .. but lets just say I...
5
by: Fredp | last post by:
Hi I was wondering if it is possible to have the various magic methods, mainly __getattr__ and __setattr__, and @property attributes called when accessing the attribute of a non-intantiated class....
7
by: James Crosswell | last post by:
I want to create a class with a static property as follows: class MyClass { private static List<MyHandlerRegisteredHandlers = new List<MyHandler>; } I then want to be able to create...
3
by: chsalvia | last post by:
In generic programming, static member functions and functors seem to be very useful. I've noticed that some libraries take the approach of using templated static member functions to provide...
4
by: Enrico | last post by:
Hi there, I have the following situation (I tryed to minimize the code to concentrate on the issue): def __getattr__(self, name): print 'A.__getattr__' if name == 'a': return 1 raise...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.