Python: passing flags to functions

前端 未结 6 2109
清酒与你
清酒与你 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:17

    you can define flag1 ...flagN as global variables, and define your function with func( *args)

    FLAG1 = 1
    FLAG2 = 2
    
    def func(*args):
       pass
    
    func(FLAG1, FLAG2)
    

    By defining flags separately, instead of using string, you can avoid typos in flags' names and some headache when debugging

提交回复
热议问题