On Mar 7, 10:14 pm, John Nagle <[EMAIL PROTECTED]> wrote: > Paul Rubin wrote: > > "C Barr Leigh" <[EMAIL PROTECTED]> writes: > > >>Help! Have I found a serious bug? > >>This seems like highly undesired behaviour to me. From the program > >>below, I get output: > > > It is intentional, not a bug, see the docs. Whether it's desirable is > > a different question. > > True. It would make sense to disallow mutable values as > initial values for optional arguments. The present behavior > is silly.
1. If you'd given it a little more thought than it took you to write this, you would perhaps realize that it is in general impossible to determine automatically whether an arbitrary object is mutable or not. 2. Even if you could determine it, it would be overly restrictive to disallow all mutable values from defaults. The fact that an object is mutable doesn't mean that the function will try to mutate it: def paintWall(ind, colormap={1:'red', 2:'blue', 5:'green'}): print "Let's paint the wall %s" % colormap[ind] George -- http://mail.python.org/mailman/listinfo/python-list