Search code examples
pythonvariablesazure-devopsglobal-variablesstring-substitution

Concatenation the string values in python


I am trying to concatenation the string values like below in the python

args = parser.parse_args()

regionCode = args.regionCode

azure_api_token = args.azure_api_token

computerName = args.computerName

targetOu = 'OU=XXX,OU=$regionCode,OU=XXX,DC=XXX,DC=XX'

in the regioncode I am fetching the value from the build parameters I am trying to assign it in the target OU $regioncode but the value is not fetching or substituting

can someone please help me with the command how to substitute the variable value into the target OU


Solution

  • To substitute a variable in a string in python you can do in many different ways.

    Here you can do:

    python 2:

    targetOu = 'OU=XXX,OU={},OU=XXX,DC=XXX,DC=XX'.format(regionCode)
    

    python 3:

    targetOu = f'OU=XXX,OU={regionCode},OU=XXX,DC=XXX,DC=XX'
    

    There are many other ways to do so. But this has been answered in so many different threads that I won't bother writing other solutions.