I like to do this to avoid list syntax:
def make_dir(path):
subprocess.run('mkdir -p'.split() + [path]) def make_dir(path):
subprocess.run('mkdir -p'.split() + [path])I’ve seen bugs where some forgot to add quotes and commas to split some arguments and the program did the wrong thing. Parent’s approach avoids that. However, things like spaces in quoted strings are not correctly handled.
I assume you meant something like subprocess.run(['mkdir', '-p', '--', *path.split()]), which in that case using shlex.split will fix your problems with quoted strings.