2 + 2 = 5

Evan Driscoll driscoll at cs.wisc.edu
Thu Jul 5 02:39:21 CEST 2012


On 7/4/2012 14:37, Paul Rubin wrote:
> I just came across this (https://gist.github.com/1208215):
> 
>     import sys
>     import ctypes
>     pyint_p = ctypes.POINTER(ctypes.c_byte*sys.getsizeof(5))
>     five = ctypes.cast(id(5), pyint_p)
>     print(2 + 2 == 5) # False
>     five.contents[five.contents[:].index(5)] = 4
>     print(2 + 2 == 5) # True (must be sufficiently large values of 2 there...)
> 
> Heh.  The author is apparently anonymous, I guess for good reason.

Probably just nostalgic for old Fortran, which, supposedly, allowed you
to change the values of literals by passing them to a function by
reference and then modifying the value.

Evan


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 552 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20120704/19cc1092/attachment.sig>


More information about the Python-list mailing list