Fredrik Lundh a écrit : > [EMAIL PROTECTED] wrote: > > >>For example: >> >> >>>>>A = [] # let's declare a "constant" here >>>>>b = A # and let's assign the constant here >>>>>b.append('1') # OOPS! >>>>>c = A >>>>>print A >> >>['1'] >> >>>>>print b >> >>['1'] >> >>>>>print c >> >>['1'] >> >>As you can see, the "constant" A can be modified this easily. But if >>there were an intuitive mechanism to declare a symbol to be immutable, >>then there won't be this problem. > > > why are you using mutable objects as constants? > > (insert obligatory "it hurts when I do this" joke here) > > btw, given a hypothetical "object that symbol points to is immutable" syntax, > what would you expect this to do ? > > >>> constant A = [] > > >>> b = [A] > > >>> # much later > >>> b[0].append('1')
That's easy, since A is a symbolic constant know at compile time, and since it's a known mutable objet, the code once compiled will be equivalent to: >>> b = [[]] >>> # much later >>> b|0].append('1') -- http://mail.python.org/mailman/listinfo/python-list