Pointers in Python
realpython.com
realpython.com
• Facts and myths about Python names and values https://nedbatchelder.com/text/names.html
and its presentation version:
• Python Names and Values https://nedbatchelder.com/text/names1.html
[0] https://github.com/micropython/micropython/ [1] https://www.microbit.org/
>>> add_one(ctypes.byref(x))
998793640If you would use pointers exclusively, then you'd have to write your own garbage collector. Also, accessing data would be more difficult, and you could not use Python's data types such as classes.
One place where pointers might be useful is if you have some strings spread across a bunch of different objects of different types and you want to do some transformation on all of them. A pointer to each of those strings would mean you could simply modify them instead of having to assign to the containing object. But you can sort of define your own pointer type with a class with one field to solve that problem. The downside of that would be all the objects would have to contain that pointer type instead of the string directly. Another alternative would be getattr/setattr (although that wouldn't work for locals). Or maybe you could rewrite to a visitor pattern.
Overall the slight benefit a pointer would provide is outweighed by the complexity it would bring of people wondering how and when to use it.
You can just use a bytearray if you want a mutable string.
So if I write
circular_linked_list = { "next": None }
circular_linked_list["next"] = { "next": circular_linked_list }
circular_linked_list = None
My linked list won't get cleaned up? I think the author should be more careful with his wording.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.