A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2000-May/004376.html below:

[Python-Dev] Constants

[Python-Dev] Constants [Python-Dev] ConstantsChristopher Petrilli petrilli@amber.org
Wed, 31 May 2000 14:17:57 -0400
Eric S. Raymond [esr@snark.thyrsus.com] wrote:
> I just looked at Jeremy Hylton's warts posting
> at <http://starship.python.net/crew/amk/python/writing/warts.html>
> 
> It reminded me that one feature I really, really want in Python 3000
> is the ability to declare constants.  Assigning to a constant should 
> raise an error.
> 
> Is this on the to-do list?

I know this isn't "perfect", but what I do often is have a
Constants.py file that has all my constants in a class which has
__setattr__ over ridden to raise an exception.  This has two things;

    1. Difficult to modify the attributes, at least accidentally
    2. Keeps the name-space less poluted by thousands of constants.

Just an idea, I think do this:

     constants = Constants()
     x = constants.foo

Seems clean (reasonably) to me.

I think I stole this from the timbot.

Chris
-- 
| Christopher Petrilli
| petrilli@amber.org



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4