Print stdout in Python without shell escape sequences

大兔子大兔子 提交于 2019-11-29 16:07:57

s.stdout in the REPL will not print it but display its repr(). Use print s.stdout to get what you are looking for.

If you do not want any escape codes consider executing it using subprocess.call() - with stdout not being a tty most programs do not output any escape sequences.

Honza Javorek

According to this GitHub issue, correct solution to the problem is to use _tty_out=False:

>>> str(git('show', format='%cN', s=True))
'\x1b[?1h\x1b=\rHonza Javorek\x1b[m\r\n\r\x1b[K\x1b[?1l\x1b>'

>>> str(git('show', format='%cN', s=True, _tty_out=False))
'Honza Javorek\n'

This is also solution for my duplicate question: Using sh, git show returns special characters - how to get plain output?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!