Re:Pointers in Python
by scardine on Sunday June 16, 2019 @08:43PM
(#20198894)
IINM the reference implementation has a cache for small integers. I wonder what happens if you try the ctypes example in the article with one of the cached integers.
[ Parent
| on HN ]
Nothing happens with the cache. According to the article you can't use a Python int, instead you have to use a ctypes.c_int and those are not cached.
This is an excellent question with a generally fun answer, at least in python 2.
https://kate.io/blog/2017/08/22/weird-python-integers/ http://hforsten.com/redefining-the-number-2-in-python.html
I found these offhand, but I'm pretty sure I saw this trick earlier than 2017.