Python colorama无法与输入配合使用? [英] Python colorama not working with input?

查看:141
本文介绍了Python colorama无法与输入配合使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天终于让colorama可以工作了,并且在打印字符串时效果很好,但是当我尝试将colorama与输入配合使用时,我遇到了每个人似乎都遇到的常见错误.

Finally got colorama working today, and it works excellent when printing strings, but I got the common error everyone seems to get when I attempted to use colorama with input.

这是我的代码:

launch = input(Fore.GREEN + "Launch attack?(Y/N): ")

输出屏幕截图:

推荐答案

在我的系统上,input()使用 if 添加的颜色

On my system, input() works with colors if you add

import sphinx.quickstart

到您的模块.

这是完整的代码.

from colorama import Fore
import colorama
import sphinx.quickstart
colorama.init()
launch = input(Fore.GREEN + "Launch attack? (Y/N): ")

(这导致两个问题:

  1. 为什么一开始它不起作用?
  2. 真正的原因是什么? –某些人可能想深入了解狮身人面像的源代码.)


N.B.如果您通过 Git Bash 中的winpty运行python,请设置convert.


N.B. if you run python via winpty from Git Bash, set convert.

colorama.init(convert=True)

否则,当前版本不会显示颜色.

Otherwise, you do not get color with the current versions.

这篇关于Python colorama无法与输入配合使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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