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

前端 未结 4 694
春和景丽
春和景丽 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:35

    You could wrap each string in parens:

    subprocess.check_output( [
      ('application'),
      ('-first-flag'),
      ('-second-flag'),
      ('-some-additional-flag'),
    ] )
    

    And btw, Python is fine with a trailing comma, so just always use a comma at the end of the line, that should also reduce errors.

提交回复
热议问题