How do you protect yourself from missing comma in vertical string list in python?

前端 未结 4 691
春和景丽
春和景丽 2021-01-12 04:07

In python, it\'s common to have vertically-oriented lists of string. For example:

subprocess.check_output( [
  \'application\',
  \'-first-flag\',
  \'-secon         


        
4条回答
  •  伪装坚强ぢ
    2021-01-12 04:26

    maybe for this particular case:

    arglist = 'application -first-flag -second-flag -some-additional-flag'
    arglist = arglist.split()
    subprocess.check_output(arglist)
    

    Or if you find yourself writing many unique lists like this make a macro that concatenates lines into a list form, so you avoid manually putting the comma.

提交回复
热议问题