On Tue, 15 Nov 2005 21:53:23 +1100, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
[...]
>It isn't always appropriate or necessary to define "constants" (and I
>sometimes wish that Python would enforce assign-once names), but they can
>help avoid some silly mistakes.
(As I'm sure you know) you can have "assign-once" names
if you are willing to spell them with a dot ;-)

 >>> N = type('',(),{'name':property(lambda _:42)})()
 >>> N.name
 42
 >>> N.name = 43
 Traceback (most recent call last):
   File "<stdin>", line 1, in ?
 AttributeError: can't set attribute

One could also write a more efficient write-once guarantee for function scope
using a decorator that munges byte code to guarantee it.

Or one could write a custom import that guarantees it for module scope.

Or one could change the language ;-)

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to