Python: passing flags to functions

前端 未结 6 2099
清酒与你
清酒与你 2021-02-09 12:27

For a long time i have been trying to figure out what is the best way to pass flags to python functions. The most straightforward way is something like:

def func         


        
6条回答
  •  时光说笑
    2021-02-09 13:05

    What about flipping it over?

    flag1, flag2, flag3, flag4, flag5, flag6 = range(6)
    
    def func(enable=[], disable=[],
             enabled_by_default=[flag5, flag6]):
        enabled = set(enabled_by_default + enabled) - set(disabled)
        if flag1 in enabled:
            ...
        if flag2 in enabled:
            ...
    
    func(enable = [flag1, flag2, flag3],
         disable = [flag6])
    

提交回复
热议问题