Compound Assignment Operators ( +=, *=, etc...)

Tom Christiansen tchrist at mox.perl.com
Thu Aug 19 22:44:43 EDT 1999


     [courtesy cc of this posting mailed to cited author]

In comp.lang.python, 
    Timothy R Evans <tre17 at pc142.cosc.canterbury.ac.nz> writes:
:x = 5
:def foo():
:    print x # works, prints 5
:def bar():
:    x = 6 # works, but doesn't change the global
:def wibble():
:    print x
:    x = 6 # this fails with NameError
:
:Seems like a good behaviour as it stops you doing dumb things.

Perhaps it could give a better error message, pretty please?  Sometimes
driving Python feels  like driving Ken Thompson's car.  It just keeps saying
"?" and you're expected to know what that means.  :-(


--tom

PS: From an old joke about Ken's treatment of error messages in ed.
-- 
    If I allowed "next $label" then I'd also have to allow "goto $label",
    and I don't think you really want that...  :-) [now works in perl5!]
            --Larry Wall in <1991Mar11.230002.27271 at jpl-devvax.jpl.nasa.gov>




More information about the Python-list mailing list