A Suggestion (please read and respond)

Hamish Lawson hamish_lawson at yahoo.co.uk
Mon Oct 30 13:02:35 EST 2000


> Variable names would have to be declared before they are used

Actually it could be argued that Python already does require you to
declare your variables, given that the semantics of assignment in
Python are more like name-binding than the value-cpoying of other
languages. That is

    x = 1

can be considered to be a declaration of a variable x of type integer
and bound to the integer object 1. Variables can be redeclared to refer
to a different object:

    x = x + 1    # now bound to the integer object 2

even one of a different type:

    x = "Hello"

You cannot use a variable that hasn't been declared, so

    print y

is illegal if y hasn't first been declared, e.g.:

    y = "A declared variable"

>From this way of looking at it, what is different about Python from
some other languages is not that Python doesn't require declaration of
variables; it's that Python allows you to *redeclare* a variable that
is already bound to another object.

Translating your request into this worldview, what you are after is a
mechanism for restricting the names that may be declared, that is, a
variable may not be declared if its name has not already been
registered as an approved variable name.

Hamish Lawson


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list