tqdm progressbar和colorama不能一起使用 [英] tqdm progressbar and colorama do not work together

查看:237
本文介绍了tqdm progressbar和colorama不能一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用colorama,但是我已经在代码中使用了tqdm.

I want to use colorama, but I already use tqdm in my code.

示例:

import colorama as color
import tqdm as tqdm  # without line it's working
print(color.Fore.GREEN + 'Green text')

在没有tqdm的情况下,它可以正常工作,但是如果导入tqdm,colorama在重新启动控制台之前不会为文本着色.我将IPython控制台与Spyder(Python 3.6)一起使用.

It's working fine without tqdm, but if I import tqdm, colorama does not color the text until I restart the console. I use IPython console with Spyder (Python 3.6).

是否可以同时使用这些软件包?

Is there a way I can use these packages together?

推荐答案

import colorama as color
import tqdm as tqdm 
import os

os.system('cls')
print(color.Fore.GREEN + 'Green text')

如果正在进行任何其他活动或您先前在终端上运行了

tqdm,则该命令将不起作用.

tqdm doesn't works if there is any other activity going on or was previously run on your terminal.

因此最好使用os.system('cls')在代码开始时清除终端屏幕. 这对我来说很好.

so its better to once clear your terminal screen at the starting of your code using os.system('cls') . This works fine for me.

这篇关于tqdm progressbar和colorama不能一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆