HoneyMoose
  • 首页
  • Java
  • Jersey
  • Jira
  • Confluence
  • U.S.
    • USRealEstate
    • U.S. Travel
    • H1B
  • 项目和网站
    • CWIKI.US
    • OSSEZ 社区
    • WIKI.OSSEZ.COM
    • BUG.OSSEZ.COM
    • RSS.OSSEZ.COM
BLOG.OSSEZ.COM
A responsive blog theme focused om user reading experience
  1. Home
  2. Computer Science
  3. This article

如何在 Python 中清屏

2021年03月12日 662Browse 0Like 0Comments

在很多时候,如果我们在控制台中使用 Python, 随着时间的推移,可能会发现屏幕越来越乱。

如下图,我们跑了不少的测试程序,在屏幕上有很多的输出。

 

python-cls-01

 

在 Windows 中,我们会使用 cls 命令清屏。

在 Python,应该怎么样才能清屏呢?

解决

其实 Python 并没有清屏幕的命令,也没有内置内置命令可以用。

但是,我们可以使用快捷键:

ctrl+l

来进行清屏。

 

python-cls-02

 

当然,如果你希望使用一个自定义函数的方法来进行清屏。

# -*- coding: utf-8 -*-

# import only system from os
from os import system, name

# import sleep to show output for some time period
from time import sleep


# define our clear function
def clear():
    # for windows
    if name == 'nt':
        _ = system('cls')

    # for mac and linux(here, os.name is 'posix')
    else:
        _ = system('clear')

    # print out some text


print('Hello CWIKIUS\n' * 10)

# sleep for 2 seconds after printing output
sleep(2)

# now call function we defined above
clear()

如上面使用的代码,我们在运行后,将会看到屏幕在退出前被清理了。

https://www.ossez.com/t/python/13375

Tags: None
Last updated:2021年03月12日

Kratos

stay absorbed stay excellent

Like
< Previous
Next >

Comments

Cancel reply

Newest Hotspots Random
Newest Hotspots Random
Java 中使用 public,private 和 protected 修饰的方法 IntelliJ IDEA 打开近期工作的项目的对话框的快捷键 民族融合的湘南典范芬香村 - 振兴绿色乡村 Java System.lineSeparator 方法 民族融合的湘南典范芬香村 - 故事与民谣 民族融合的湘南典范芬香村 - 民俗风情之崇文重教
JAVA程序员写的接口没有PHP程序员体验好Java 虚拟机的概念是怎么来的Protocol buffers 的问题和滥用Discourse 自定义头部链接(Custom Header Links)GRPC MacOS M1 处理器的问题靠山面水的诗意适居 —— 传统村落水口山镇大皮口村
行李牌怎样保护隐私 Confluence 6 设置 Oracle 数据库准备 Confluence 6 在升级过程中查看合并日志 MariaDB CentOS 安装的时候如何确定 Repo 地址 Confluence 6 警告的类型 Spring Boot 2.4 从早期版本进行升级
Categories
  • Akka
  • Algorithm(算法)
  • AMQP
  • Angular
  • CI
  • Compile And CI
  • Computer Science
  • Confluence
  • DataBase
  • Gradle
  • H1B
  • Hibernate
  • IDE
  • Java
  • Jersey
  • Jira
  • MariaDB
  • PrestaShop
  • Spring
  • Spring Batch
  • U.S.
  • U.S. Travel
  • USRealEstate
  • 我的小厨

COPYRIGHT © 2020 HoneyMoose. ALL RIGHTS RESERVED.

THEME CWIKIUS.CN MADE BY VTROIS