On Wednesday 27 April 2016 02:59, Chris Kaynor wrote: > On Tue, Apr 26, 2016 at 9:32 AM, Steven D'Aprano <st...@pearwood.info> > wrote: > >> Actually immutable, short of doing wicked things with ctypes. >> > > By wicked things with ctypes, do you mean something like this? By no means > do I suggest this actually be used by anybody for any reason. > > Tested with '2.7.10 (default, Jul 14 2015, 19:46:27) \n[GCC 4.2.1 > Compatible Apple LLVM 6.0 (clang-600.0.39)]' > > import ctypes > def changeTuple(tuple, index, newValue): > obj = ctypes.cast(id(tuple), ctypes.POINTER(ctypes.c_long)) > obj[3+index] = id(newValue) > >>>> a = ('a','b','c') >>>> changeTuple(a, 0, 1) >>>> a > (1, 'b', 'c') >>>> changeTuple(a, 1, 3) >>>> a > (1, 3, 'c')
You're a bad, bad man :-) -- Steve -- https://mail.python.org/mailman/listinfo/python-list