Re: lists: += vs. .append() & oddness with scope of variables

2006-03-05 Thread Terry Reedy
"Sandro Dentella" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I'd like to understand why += operator raises an error while .append() > does > not. Your mistake is thinking of '+=' as an operator. In Python terms it is not, any more than '=' is. In Python, neither 'a=b' nor

Re: lists: += vs. .append() & oddness with scope of variables

2006-03-05 Thread Scott David Daniels
Duncan Booth wrote: > Sandro Dentella wrote: > >> I'd like to understand why += operator raises an error while .append() >> does not. My wild guess is the parses treats them differently but I >> cannot understand why this depends on scope of the variables (global >> or class variables): > > >

Re: lists: += vs. .append() & oddness with scope of variables

2006-03-05 Thread Duncan Booth
Sandro Dentella wrote: > I'd like to understand why += operator raises an error while .append() > does not. My wild guess is the parses treats them differently but I > cannot understand why this depends on scope of the variables (global > or class variables): > > > a = [0] > > class foo(object)

Re: lists: += vs. .append() & oddness with scope of variables

2006-03-05 Thread Felipe Almeida Lessa
Em Dom, 2006-03-05 às 11:49 +, Sandro Dentella escreveu: > class foo(object): > > def __init__(self): > print "a: ", a > # += does not work if 'a' is global > #a += [1] > a.append(2) > print "a= ", a Try with: a = [0] class foo(object): def

lists: += vs. .append() & oddness with scope of variables

2006-03-05 Thread Sandro Dentella
I'd like to understand why += operator raises an error while .append() does not. My wild guess is the parses treats them differently but I cannot understand why this depends on scope of the variables (global or class variables): a = [0] class foo(object): def __init__(self): print