有谁知道清算后是否有可能将输出修复到控制台的顶部?
我正在努力构建赌场应用程序,并且我希望用户的登录信息(用户名& Balance)即使清除后也将其固定到控制台上。我必须清除控制台,因为那时我将不想再看到很多输入和印刷品。不确定唯一的方法是清除控制台,然后再重印我想要的信息或是否有其他方法。下面我包括了一个我想要的示例。谢谢你!
代码:
balance = 100
user = 'username'
print(f"Balance: {balance} User: {user}") # I want to keep this output constantly visible, even after clearing my console
# dummy output I want to eventually clear
for i in range(200):
print('hi')
clearConsole()
控制台:
平衡:100 用户:用户名
I'm working on building a casino application and I want the user's login info (username & balance) to be fixed to the console even after clearing it. I have to clear the console because then there's going to be a bunch of inputs and prints that I don't want to be visible anymore. Not sure if the only way is to just clear the console and it reprint the information I want or if there is alternative ways. Below I've included an example of something I would like. Thank you!
Code:
balance = 100
user = 'username'
print(f"Balance: {balance} User: {user}") # I want to keep this output constantly visible, even after clearing my console
# dummy output I want to eventually clear
for i in range(200):
print('hi')
clearConsole()
Console:
Balance: 100
User: username
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要的代码是:
the code you'd need for that is this:
干得好!
使用子过程。
假设您正在使用MacOS,
如果您使用的是Windows,请将呼叫功能更改为
Here you go!
Use subprocess.
Assuming that you are using MacOS,
If you are using Windows, change the call function to