Python console and text output from Ping including \\n\\r [duplicate]
This question already has answers here : Convert bytes to a string (18 answers) Closed 6 years ago . I dont know what is happening, but when I am printing to the console or to a text file, the newline (\n) is not functioning but rather showing in the string. Any idea how to avoid this in both the console and the text file? My code: import subprocess hosts_file = open("hosts.txt","r") lines = hosts_file.readlines() for line in lines: line = line.strip() ping = subprocess.Popen(["ping", "-n", "3",line],stdout = subprocess.PIPE,stderr = subprocess.PIPE) out, error = ping.communicate() out = out