Search code examples
pythonconventions

python declaration of constant beginning with number


I have a python module with definitions of constants. They look like so:

30KHZ = 0b000
125KHZ = 0b001
250KHZ = 0b010
1MHZ = 0b011

Obviously, these are not allowed names. One way of to deal with this is to prepend names with something. Names like _30KHZ look nice, but they mess with static analyzers. Names like S_30KHZ or F30KHZ are allowed, but they look awkward and the meaning of the S_ or F may be unclear. Another way is to rotate the name like so: KHZ30. But is doesn't look good either.

How to name such constants to make their meaning obvious to the user?


Solution

  • I would probably put these in a dictionary:

    BITMAPS = {
        "30KHZ": 0b000,
        "125KHZ": 0b001,
        "250KHZ": 0b010,
        "1MHZ": 0b011,
    }