Skip to content
Advertisement

How to indent correctly multi-line list of arguments inside function call in Python [closed]

I want to create this multi-line function call. The examples that I find for nested constructs they assume that there is a character starting each line i Cannot find an example where a bracket [ is followed by a parenthesis ( without anything in between.

So how would I format this:

  subprocess.run(['docker-compose', '-f', 'docker-compose.test.yml', '-f',
                   'docker-compose.services.yml', '-f', 'docker-compose.dev.yml', 'down'],
                 stdout=subprocess.DEVNULL
  )

where should the bracket go? How should i format the list of arguments? Is it ok if I have multiple on the same line? Or should each argument has its own line

Advertisement

Answer

You can do something like this

import subprocess

subprocess.run(
    [
        'docker-compose', '-f', 'docker-compose.test.yml', '-f',
        'docker-compose.services.yml', '-f', 'docker-compose.dev.yml', 'down'
    ],
    stdout=subprocess.DEVNULL
)
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement