如何删除python控制台中的最后一个输出,而不是最后一个行?

发布于 2025-01-10 09:39:26 字数 518 浏览 0 评论 0原文

我正在制作一个简单的文本冒险游戏来练习。我希望玩家在进一步进入某个场景后能够回溯,例如在走下楼梯后,我希望他们能够选择“后退”并能够原路返回。

我已经弄清楚了其中的各个方面,除了:如何清除弹出的消息,告诉他们刚刚进入的场景。

我有代码将它们的响应设为变量,然后确定该变量是否是可行选项的一组列表之一,如果不是,则将它们循环回开头并使用代码行 print(" \033[A \033[A")

但是,此代码仅删除最后代码,该代码根据屏幕比例和不同设备的不同而有很大差异,而不是最后的输出,这是向他们描述场景的完整消息。

有谁知道一段代码可以

  • 删除控制台的整个最后输出,在本例中是打印的一行代码,超过一行,可能会扩展多达 8-10 行,详细说明他们的场景,或者
  • 清除控制台,然后将它们返回到我预定义的起点(示例:def start0():),因为在我清除控制台后,代码 start0() 不起作用。

I'm making a simplistic text adventure game for practice. I want players to be able to backtrack once they go farther into a scenario, for example after they go down a staircase I want them to be able to have "back" as an option and be able to retrace their steps.

I've already figured out every aspect of that except: How to clear the message that popped up telling them about the scenario they just entered.

I have code making their response a variable, and then determining if that variable is one of a set list of viable options, and if not looping them back to the start and deleting their previous entry with the line of code print("\033[A \033[A")

However, this code only deletes the last line of code, which varies wildly depending on screen ratio and different devices, and not the last output, which is the entire message that described to them the scenario.

Does anyone know a piece of code that can either

  • delete the entire last output of the console, in this case a printed line of code which exceeds one line and may extend for as many as 8-10 lines, detailing their scenario, or
  • clear the console and then warp them back to my predefined starting point (Example: def start0():), because after I clear the console the code start0() doesn't work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文