I am trying to get a config from a juniper router and I have the following problem:
After setting this
stdin, stdout, stderr = client1.exec_command(\
An alternative to what you want is splitting your string into a list of strings (per line).
mystr = 'a\nb\nc'
mystr = mystr.split(sep='\n')
print(mystr)
#this will be your print output:['a', 'b', 'c']
for s in mystr:
print(s)
#your print output:
#a
#b
#c
This also works:
CONFIG = """{}""".format(CONFIG)
If you're running this in the Python interpreter, it is the regular behavior of the interpreter to show newlines as "\n" instead of actual newlines, because it makes it easier to debug the output. If you want to get actual newlines within the interpreter, you should print
the string you get.
If this is what the program is outputting (i.e.: You're getting newline escape sequences from the external program), you should use the following:
OUTPUT = stdout.read()
formatted_output = OUTPUT.replace('\\n', '\n').replace('\\t', '\t')
print formatted_output
This will replace escaped newlines by actual newlines in the output string.