[Python-ideas] Should Python have user-defined constants?

Serhiy Storchaka storchaka at gmail.com
Tue Nov 21 05:03:17 EST 2017


21.11.17 11:34, Saeed Baig пише:
> Serhiy asked, in relation to constants, “To do what? What problem do you 
> need to solve?”. No problem in particular, to be honest. I just thought 
> they’d be nice since they’d increase confidence that my 
> variables-intended-to-be-constants wouldn’t get reassigned, and just to 
> increase readability/explicitness to other programmers.

For increasing readability/explicitness you can use a name convention 
(UPPER_CASE), comments and documentation.

As for increasing confidence that your 
variables-intended-to-be-constants wouldn’t get reassigned, you can use 
read-only properties. This is a tricky to implement read-only properties 
for modules, but see PEP 562 which should help to do this.

Please don't use GIGANTIC font in your messages.

And please don't create a new thread when answer.

And *please* don't include unrelated text in your messages.



More information about the Python-ideas mailing list