In python, it’s common to have vertically-oriented lists of string. For example:
subprocess.check_output( [
'application',
'-first-flag',
'-second-flag',
'-some-additional-flag'
] )
This looks good, readable, don’t violate 80-columns rule… But if comma is missed, like this:
subprocess.check_output( [
'application',
'-first-flag' # missed comma here
'-second-flag',
'-some-additional-flag'
] )
Python will still assume this code valid by concatenating two stings :(. Is it possible to somehow safeguard yourself from such typos while still using vertically-oriented string lists and without bloating code (like enveloping each items inside str())?
You could wrap each string in parens:
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.