Ideas about how software should behave

Chris Angelico rosuav at gmail.com
Tue Nov 7 14:59:55 EST 2017


On Wed, Nov 8, 2017 at 6:44 AM, Stefan Ram <ram at zedat.fu-berlin.de> wrote:
> Chris Angelico <rosuav at gmail.com> writes:
>>sure what your point is. None, False, and True are all keywords, not
>>built-ins, so you can't assign to them (any more than you could assign
>>to a literal integer).
>
> |Python 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)] on win32
> |Type "help", "copyright", "credits" or "license" for more information.
> |>>>
> |>>> import ctypes
> |>>>
> |>>> value = 2
> |>>> ob_ival_offset = ctypes.sizeof(ctypes.c_size_t) + ctypes.sizeof(ctypes.c_voidp)
> |>>> ob_ival = ctypes.c_int.from_address(id(value)+ob_ival_offset)
> |>>> ob_ival.value = 3
> |>>>
> |>>> print 2
> |3

That's still not assigning to a literal; that's mutating a cached
object. There's a difference :)

Also, once you start messing with ctypes like this, all language
guarantees are out the window.

ChrisA



More information about the Python-list mailing list