简体   繁体   中英

How to get print to format its output in python?

print(reprt('Hello\\nHello')) will print b'Hello\\nHello' and I would like it to print

Hello
Hello

instead. The reason for this is that some functions such as subprocess.check_output send a repr output.

params = r'"C:\cygwin64\bin\bash.exe" --login -c ' + r"""'ls "C:\Users"'""" 

print(subprocess.check_output(params, shell=True))

then dont use repr just use

print("hello\nhello")

demo

tracing.py

print("hello\nhello")

otherscript.py

import subprocess

print subprocess.check_output('python tracing.py')

output

hello
hello

you could try this:

>>> eval(repr("Hello"))
'Hello'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM