changing local namespace of a function

Bo Peng bpeng at rice.edu
Sat Feb 5 11:01:57 EST 2005


Nick Coghlan wrote:

> 
> If you want to add more calculated properties to the data manipulator, 
> simply define additional calculator methods, and define the attribute 
> with make_prop.

This has became really appealing....

You know, I have a deep root in C/C++ so performance is the king and 
hacking is part of my daily life. Time to change now. :)

My original problem was that I need to manipulate and create dictionary 
items in situ and since there are so many "d['key']"s, I would like to 
make my code easier to read (and save some key strokes) by using "d.key" 
or simply "key", without sacrificing performance. OOP seemed to be 
irrelevant.

But this on-demand calculation (quote: make first call to z automatic) 
is *really* good! I can calculate self._data.stat_a = self._data.stat_b 
+ 1 without worrying about the status of stat_b and users can access any 
   value in the dictionary, original or calculated, in a uniform and 
easier way! This makes my program instantly easier to use.

I can not say enough thank you for this.

Bo



More information about the Python-list mailing list