total idiot question: +=, .=, etc...

Michael P. Reilly arcege at shore.net
Thu Jun 24 17:05:06 EDT 1999


Joshua Rosen <rozzin at geekspace.com> wrote:
: Reimer Behrends wrote:
:> To remind you, pretty much every single OO language other
:> than Python does not require you to add a self; yet at the same time
:> they have per-method and per-object data. It's a matter of how you
:> declare it.

: Of course, Python doesn't have pre-assignment declarations of variables....

Not quite true.. global variables must declared as such within a local
scope, even before any assignment.

  $ cat foo.py
  def foo():
    global bar
    bar = "Joe's"
  foo()
  print bar
  $ python foo.py
  Joe's
  $

Formal function parameters (which are placed in the local namespace)
must be declared before envocation.

So there are five ways to..

No, two sir!

But it IS true that within functions (and methods and class definitions
and...) that unqualified local variable names do not have to be
declared.

It is also true that a lot of speghetti code can more easily come out
of "OO" languages with intermeshed object namespaces (this said as a
software configuration manager of many years, organizations and
projects writing in different OO languages).  Having to qualify the
names leads to fewer scoping problems down the road (when someone else
is picking up the code and porting it).

  -Arcege





More information about the Python-list mailing list