How to use quotation marks inside quotation marks and exchange words inside the argument?

Asked

Viewed 6,223 times

-1

Rotating the

os.system("reg add "caminho\caminho\caminho\caminho\"")

and if you can do more, you have a way for me to pick a word in the middle of that command and replace it with another??

  • Welcome to the site. Take a look at my answer and see if it helps you.

1 answer

1

To use quotes within a string definition, you need to escape it with \.

Thus:

"meu nome é \"wallace\"

The result will be:

'meu nome é "wallace"'

You could also replace double quotes with single quotes, to make this definition easier to read:

'meu nome é "Wallace"'

To replace a specific section, use the method replace of his str.

Thus:

'meu nome é Robin'.replace('Robin', 'Wallace')

The result will be:

'meu nome é Wallace'

My considerations and recommendations

To execute this command, I would not escape the string, and yes, I would use the str, to improve readability, thus:

cmd = 'reg add "{0}"'.format("caminho\caminho\caminho")

os.system(cmd)

Or still using the operator % to define the str.

caminho = "caminho\caminho\caminho"
cmd = "reg add "%s"' % caminho;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.