Why are functions atomic?

7stud bbxx789_05ss at yahoo.com
Tue May 1 10:35:15 EDT 2007


On May 1, 5:06 am, Michael <michael.for... at gmail.com> wrote:
> Why are functions atomic?  (I.e. they are not copied.)
>
> For example, I would like to make a copy of a function so I can change
> the default values:
>
> >>> from copy import copy
> >>> f = lambda x: x
> >>> f.func_defaults = (1,)
> >>> g = copy(f)
> >>> g.func_defaults = (2,)
> >>> f(),g()
>
> (2, 2)
>
> I would like the following behaviour:
>
> >>> f(),g()
>
> (1,2)
>
> I know I could use a 'functor' defining __call__ and using member
> variables, but this is more complicated and quite a bit slower.  (I
> also know that I can use new.function to create a new copy, but I
> would like to know the rational behind the decision to make functions
> atomic before I shoot myself in the foot;-)
>
> Thanks,
> Michael.

Does deepcopy work?




More information about the Python-list mailing list