Python Class Static Variable and Method

July 3, 2019
class SheetCol:
    INDEX = 'A'
    SYMBOL = 'B'
    PRICE = 'C'
    QUANTITY = 'D'

    @staticmethod
    def to_index0(char):
        return ord(char) - 65
    # A = 0
    # B = 1

Usage

indexCol = SheetCol.to_index0(SheetCol.INDEX)   # A=0
symbolCol = SheetCol.to_index0(SheetCol.SYMBOL) # B=1
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.