Python's "only one way to do it" philosophy isn't good?

Douglas Alan doug at alum.mit.edu
Sat Jun 23 15:14:15 EDT 2007


Steven D'Aprano <steve at REMOVE.THIS.cybersource.com.au> writes:

> But if you really want declarations, you can have them.
>
>>>> import variables
>>>> variables.declare(x=1, y=2.5, z=[1, 2, 4])
>>>> variables.x = None
>>>> variables.w = 0
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "variables.py", line 15, in __setattr__
>     raise self.DeclarationError("Variable '%s' not declared" % name)
> variables.DeclarationError: Variable 'w' not declared

Oh, I forgot to mention that I work a lot on preexisting code, which I
am surely not going to go to all the effort to retype and then retest.
With the "let" and "set" macros I can use "set" without a matching
"let".  "set" just checks to make sure that a variable already exists
before assigning to it, and "let" just prevents against
double-declarations.  They can be used independently or together.
With your "variables" class, they have to be used together.

|>oug



More information about the Python-list mailing list