[Tutor] Python cashes low integers? How? Where?

Dick Moores rdm at rcblue.com
Mon Aug 9 19:51:39 CEST 2004


Danny Yoo wrote at 10:30 8/9/2004:
>The implementors of Python added some efficiency tricks to the system, and
>some of these tricks are not duplicated in other implmentations of Python.
>We had a small discussion about this a few months ago:
>
>     http://mail.python.org/pipermail/tutor/2004-May/029625.html
>
>It turns out that Python does try to internalize ("intern") small
>name-like strings in a cache.  The rationale is that these names are
>likely to recur in a program, and so it's probably worthwhile to save them
>around, to avoid having to churn so many strings out.
>
>So yes, 'querty' and 'Dick', being name-like string literals, will get
>cached by CPython 2.3.3.  But you should not really need to worry about
>this.  *grin* It's possible that the caching strategy that the
>implementors choose might change; it's not set in stone that Python should
>do this kind of caching.

Thanks very much, Danny. My curiosity about this has been satisfied for 
the time being, and I can return to more practical matters in my study of 
Python.

Dick




More information about the Tutor mailing list