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

Douglas Alan doug at
Sat Jun 23 21:14:15 CEST 2007

Steven D'Aprano <steve at> 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 "", 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.


More information about the Python-list mailing list