[Python-Dev] Re: Caching objects in memory
facundobatista at gmail.com
Tue Apr 26 18:22:15 CEST 2005
On 4/25/05, Guido van Rossum <gvanrossum at gmail.com> wrote:
> > I was in my second class of the Python workshop I'm giving here in one
> > Argentine University, and I was explaining how to think using
> > name/object and not variable/value.
> > Using id() for being pedagogic about the objects, the kids saw that
> > id(3) was always the same, but id() not. I explained to them that
> > Python, in some circumstances, caches the object, and I kept them
> > happy enough.
> > But I really don't know what objects and in which circumstances.
> Aargh! Bad explanation. Or at least you're missing something:
Not really. It's easier for me to show that id(3) is always the same
and id() not, and let the kids see that's not so easy and you'll
have to look deeper if you want to know better.
If I did id(3) and id(500), then the difference would look more
subtle, and I would had to explain it longer. Remember, it was the
second day (2 hours per day).
> implementation is free to use caching. In practice, I believe ints
> between -5 and 100 are cached, and 1-character strings are often
> cached (but not always).
These are exactly my doubts, ;).
More information about the Python-Dev