Search code examples
pythonpython-3.xconcatenation

String injection of Python3 command-line args


New to Python, I have the following script:

#!/usr/bin/env python3
import sys

env = sys.argv[1:]  # The name of the environment we're executing over ('Dev', 'Test', 'Prod', etc)

print('Executing against ' + env)

Above, the script should be invoked with an env argument that is then printed out to STDOUT.

Is there any more elegant way to inject the env variable into the string being printed (so I don't have that nasty-looking + concatenation going on)?


Solution

  • Try this:

    print('Executing against {}'.format(env))