On Thu, Jul 19, 2007 at 01:03:50PM -0600, Jim Meier wrote:
>
> On 19-Jul-07, at 12:22 PM, Steven Kurylo wrote:
>
> >>Perhaps a little odd, but its not a problem once you are used to it.
> >
> >I think its bad form to allow you to read a variable, but then do some
> >silent slight of hand if you try to write to it. Its the silent part
> >that bothers me.
>
> Yup. It's a bit of a deviation from python's normal explicit >
> implicit ideology.
>
> >And its not universally applied either:
> >
> >list = [ 'a','b' ]
> >def foo():
> > print list
> > list.append('c')
> > print list
> >foo()
> >print list
> >
> >Gives
> >
> >['a', 'b']
> >['a', 'b', 'c']
> >['a', 'b', 'c']
> >
> >So I can append to a list inside a function, so its not read only.
> >Yes I understand why. Its still inconsistent.
>
> No; the rule has applied here, of course: it's about bindings, not
> about values. A python variable is a binding *only*; that the list it
> is bound to is mutable does not mean you've modified the binding.
>
> That's why the scope rule is usually not an issue: globals are
> usually mutable values.
>
> It's a bit rare for python code to be noodling with a lot of globals
> - that sort of thing is usually wrapped up in a class.
A similar example to illustrate this would be:
list = list + ['c']
instead of:
list.append('c')
Received on Thu Jul 19 13:56:00 2007
This archive was generated by hypermail 2.1.8 : Thu Jul 19 2007 - 13:56:03 CST