Running the
os.system("reg add "caminho\caminho\caminho\caminho\"")
And if there is more, how can I choose a word in the middle of this command and replace with another one?
Running the
os.system("reg add "caminho\caminho\caminho\caminho\"")
And if there is more, how can I choose a word in the middle of this command and replace with another one?
To use quotation marks inside a string definition, you need to escape it with \
.
So:
"meu nome é \"wallace\"
The result will be:
'meu nome é "wallace"'
You could also substitute double quotation marks for single quotes to make it easier to read:
'meu nome é "Wallace"'
To replace a specific snippet, use the replace
method of your str
.
So:
'meu nome é Robin'.replace('Robin', 'Wallace')
The result will be:
'meu nome é Wallace'
To execute this command, I would not escape the string, but rather, I would use the formatting of str
, to improve readability, like this:
cmd = 'reg add "{0}"'.format("caminho\caminho\caminho")
os.system(cmd)
Or even using the %
operator to set str
.
caminho = "caminho\caminho\caminho"
cmd = "reg add "%s"' % caminho;