On Thu, Nov 19, 2015 at 11:02 AM, Ian Kelly <ian.g.ke...@gmail.com> wrote: > On Wed, Nov 18, 2015 at 4:22 PM, Chris Angelico <ros...@gmail.com> wrote: >> On Thu, Nov 19, 2015 at 10:14 AM, BartC <b...@freeuk.com> wrote: >>> So, looking at some source code, a default value for certain types is only >>> certain to be that value for the very first call of that function? >> >> On the contrary, it is certain always to be that exact object. > > "Certain" may be a bit overly strong. > >>>> def f(x=42): > ... return x > ... >>>> f() > 42 >>>> f.__defaults__ = (43,) >>>> f() > 43
I'll raise you one. >>> def f(x=42): ... return x ... >>> f() 42 >>> import ctypes >>> ctypes.c_int.from_address(id(43)+ ctypes.sizeof(ctypes.c_size_t) + >>> ctypes.sizeof(ctypes.c_voidp)).value=42 >>> f.__defaults__ = (43,) >>> f() 42 >>> Nothing is certain in Python. And two wrongs can make a... hmm... no, this is not a right. It is not a privilege either. It is a dastardly trick played on people's minds. ChrisA -- https://mail.python.org/mailman/listinfo/python-list