On Wed, Dec 4, 2019 at 5:13 PM Greg Ewing <greg.ew...@canterbury.ac.nz> wrote: > > On 4/12/19 12:53 pm, Soni L. wrote: > > Okay, sometimes it's also used for that. But the main use-case is for > > lowering RAM usage for immutable objects. > > Citation needed. If that's true, why does Python intern > names used in code, but not strings in general? I'd say > because looking names up in dicts benefits enormously > from being able to quickly compare for equality. >
It's a trade-off between the work needed to intern every string, and the memory savings from reusing them. Some languages do indeed guarantee that EVERY string (not just literals) is interned. CPython has a weaker policy (and Python-the-language doesn't have any guarantee), but if you want to create a Python interpreter that values memory usage above all else, one logical thing to do would indeed be to intern everything. ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/B2XRA5ZXNFLS6DS5ZDHXHZ6GW2S4GO6P/ Code of Conduct: http://python.org/psf/codeofconduct/