Creating a local variable scope.

Jean-Michel Pichavant jeanmichel at sequans.com
Mon Nov 30 06:02:53 EST 2009


Steven D'Aprano wrote:
> On Mon, 30 Nov 2009 02:11:12 +0100, Alf P. Steinbach wrote:
>
>   
>> I think if one could somehow declare names as const (final, readonly,
>> whatever) then that would cover the above plus much more.
>>     
>
> Having real constants is one feature that I miss. Because Python doesn't 
> have constants, I find I've lost the discipline to avoid "magic 
> numbers" (and strings) in my code.
>
>
>   
I don't get you, this can be easily avoid with a strong naming 
convention. I mean, despite they are not really constants, you can still 
use variables to name your numbers and string, to give the reader a 
usefull hint on the meaning of your code. Yet it is still a matter of 
discipline, it is sometimes very tempting to put the string directly 
(unlike numbers string can be meaningful sometimes)

JM



More information about the Python-list mailing list