Ric*_*rdo 4 python printing terminal
是否有一个优雅的解决方案可以在Python中执行此shell脚本而不导入os?
tput cup 14 15; echo -ne "\033[1;32mtest\033[0m" ; tput cup 50 0
Run Code Online (Sandbox Code Playgroud)
这只是在我心中了一段时间:)
谢谢
鉴于
tput cup 14 15 | cat -v显示^[[15;16H整个建议的脚本将生成以下 Python 脚本:
import sys
sys.stdout.write("\033[15;16H\033[1;32mtest\033[m\033[51;1H")
# and a possible sys.stdout.flush() here, depending on your needs
Run Code Online (Sandbox Code Playgroud)
感谢Ignacio Vazquez-Abrams的意见,这是朝正确方向的巨大推动。最后,我想到了这个小代码,它将帮助我征服世界:)
from curses import *
setupterm()
#cols = tigetnum("cols")
#lines = tigetnum("lines")
#print str(cols) + "x" + str(lines)
place_begin = tparm(tigetstr("cup"), 15, 14)
place_end = tparm(tigetstr("cup"), 50, 0)
print place_begin + "-- some text --" + place_end
Run Code Online (Sandbox Code Playgroud)
@ TZ.TZIOY,谢谢,我认为使用stdout而不是使用print确实是更好的解决方案。