How can I create customized classes that have similar properties as 'str'?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Nov 24 19:42:46 EST 2007


On Sat, 24 Nov 2007 14:58:50 -0800, George Sakkis wrote:

> On Nov 24, 4:59 pm, Steven D'Aprano
> 
> <st... at REMOVE-THIS-cybersource.com.au> wrote:
>> On Sat, 24 Nov 2007 03:44:59 -0800, Licheng Fang wrote:
>> > On Nov 24, 7:05 pm, Bjoern Schliessmann <usenet-
>> > mail-0306.20.chr0n... at spamgourmet.com> wrote:
>> >> Licheng Fang wrote:
>> >> > I find myself frequently in need of classes like this for two
>> >> > reasons. First, it's efficient in memory.
>>
>> >> Are you using millions of objects, or MB size objects? Otherwise,
>> >> this is no argument.
>>
>> > Yes, millions.
>>
>> Oh noes!!! Not millions of words!!!! That's like, oh, a few tens of
>> megabytes!!!!1! How will a PC with one or two gigabytes of RAM
>> cope?????
>>
>>
> Comments like these make one wonder if your real life experience with
> massive data matches even the one tenth of your self-importance and need
> to be snarky in most of your posts.

I cheerfully admit to never needing to deal with "massive data".

However, I have often needed to deal with tens and hundreds of megabytes 
of data, which IS NOT MASSIVE amounts of data to deal with on modern 
systems. Which was my point. 


> To the OP: yes, your use case is quite valid; the keyword you are
> looking for is "memoize". You can find around a dozen of recipes in the
> Cookbook and posted in this list; here's one starting point:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413717.

This has nothing, absolutely NOTHING, to do with memoization. Memoization 
trades off memory for time, allowing slow functions to return results 
faster at the cost of using more memory. The OP wants to save memory, not 
use more of it.



-- 
Steven.



More information about the Python-list mailing list