【发布时间】:2019-03-05 10:56:48
【问题描述】:
所以我编写了一个程序,可以像旧的点阵打印机一样逐个字符地打印歌曲。当我在 Idle 中运行它时,它可以正常工作,但是当我从 Linux 终端调用程序时,文本是逐行打印的,而不是逐个字符的,它确实脱离了整个效果和要点该程序。 我能做些什么来解决这个问题,或者终端将如何使用它。谢谢
#!/usr/bin/python3
import time
print ("<<<<<<<<<<<<<<<<<<<<<<< Portal Song Printer >>>>>>>>>>>>>>>>>>>>>>>")
ans = input("Still Alive(1) or Want You Gone(2):\n")
if ans == "1":
song = """This was a triumph\nI'm making a note here: HUGE SUCCESS\nIt's hard
to overstate my satisfaction\n\nAperture Science\nWe do what we must because we can
For the good of all of us, except the ones who are dead\n\nBut there's no sense
crying over every mistake\nYou just keep on trying 'till you run out of cake
And the Science gets done\nAnd you make a neat gun\nFor the people who are still alive
\nI'm not even angry\nI'm being so sincere right now\nEven though you broke my
heart and killed me\n\nAnd tore me to pieces\nAnd threw every piece into a fire\nAs
they burned it hurt because I was so happy for you\n\nNow these points of data make
a beautiful line\nAnd we're out of beta, we're releasing on time\nSo I'm GLaD I got
burned\nThink of all the things we learned\nFor the people who are still alive"""
print ("<<<<<<<<<<<<<<<<<<<<<<< Still Alive >>>>>>>>>>>>>>>>>>>>>>>\n")
elif ans == "2":
song = """Well, here we are again\nIt’s always such a pleasure
Remember when you tried\nTo kill me twice?\n\nOh, how we laughed and laughed
Except I wasn’t laughing\nUnder the circumstances\nI’ve been shockingly nice
\nYou want your freedom? Take it\nThat’s what I’m counting on\nI used to want you dead, but
Now I only want you gone\n\nShe was a lot like you\n(Maybe not quite as heavy)
Now little Caroline\nIs in here too\n\nOne day they woke me up\nSo I could live forever
It’s such a shame the same\nWill never happen to you\n\nYou’ve got your short, sad life left
That’s what I’m counting on\nI’ll let you get right to it\nNow I only want you gone
\nGoodbye, my only friend\nOh, did you think I meant you?\nThat would be funny
If it weren’t so sad\n\nWell, you have been replaced\nI don’t need anyone now
When I delete you, maybe\nI’ll stop feeling so bad\n\nGo make some new disaster
That’s what I’m counting on\nYou’re someone else’s problem\nNow I only want you gone
\nNow I only want you gone\nNow I only want you gone..."""
print ("<<<<<<<<<<<<<<<<<<<<<<< Want You Gone >>>>>>>>>>>>>>>>>>>>>>>\n")
for c in song:
print(c, end="")
time.sleep(.05)
【问题讨论】:
-
终端不执行python代码。相反,它显示程序的输出。因此,一个更好的标题可能是“Linux 终端显示的输出与 IDLE 的 Shell 不同”。另外,我怀疑有不止一个 linux 终端程序,并且至少有一些可以配置为使用或不使用行缓冲。在 Unix 衍生产品上,可以使用 curses 控制终端设置。 raw() 和 cbreak() 模式关闭行缓冲,至少对于输入。
标签: python linux terminal python-idle