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

Issue

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

Solution

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
)

Answered By – prnvbn

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published