pylearn
pylearn

Reputation: 9559

python - send a command with 3 backslashes

Editing to make question short and precise.

y = 7
command_to_send = 'command=\\\\\\"set value {0}\\\\\\\"'.format(y)

How can I get output of command_to_send as command=\\\"set value 7\\\" so that I can pass command_to_send to some other function.

Upvotes: 1

Views: 235

Answers (2)

DatHydroGuy
DatHydroGuy

Reputation: 1116

command = '\\\\\\"set value 0\\\\\\\"'

print("command={0}".format(command))

Produces output:

command=\\\"set value 0\\\"

If you want to assign you value from a variable, then you can do this:

y = 7
command_to_send = 'command=\\\\\\"set value {0}\\\\\\\"'.format(y)

print(command_to_send)

Upvotes: 0

Felix
Felix

Reputation: 6359

Using a raw string:

command = r"\\\"

Using a regular string:

command = "\\\\\\"

Upvotes: 3

Related Questions