Python string format

Tags: , , ,



I have defined the string variable

value=“c:/program files/tm su/usr”

I need to use this variable in another string like

Bashcmd=“Override project={value}”

I tried adding the rf option like this

Bashcmd =rf“Override {value}”

But it’s printing only until c:/program, white spaces are neglected. Is there any way to use entire path in Bashcmd and can’t remove spaces in directory path because many system share same paths.

Answer

You can format strings like this:

value="c:/program files/tm su/usr"
Bashcmd=f"Override project="{value}""

or you can simply concatenate the string like this:

Bashcmd="Override project=""+value+"""


Source: stackoverflow