Python 3.2 中的 Colorama 断言错误
我最近开始使用 Python 3.2,之前从未尝试过编程。我将 colorama 文件夹复制到 C:\Python32\lib 中的 lib 目录,然后在尝试基于文本的冒险游戏时编写了以下代码:
import colorama
from colorama import Fore, Back, Style
colorama.init()
notedaction = "You have gained a SWORD AND SHIELD!"
uniqueskill = "strength"
if 'strength' in uniqueskill.lower():
time.sleep(3)
print('As you are a Warrior, I shall supply you with the most basic tools every Warrior needs.')
time.sleep(3)
print('A sword and shield.')
time.sleep(1)
print(Fore.RED + notedaction)
但是,每当我到达这部分代码时,都会出现以下错误:
File "<pyshell#10>", line 7, in <module>
print(Fore.RED + notedaction)
File "C:\Python32\lib\colorama\ansitowin32.py", line 34, in write
self.__convertor.write(text)
File "C:\Python32\lib\colorama\ansitowin32.py", line 115, in write
self.write_and_convert(text)
File "C:\Python32\lib\colorama\ansitowin32.py", line 140, in write_and_convert
self.convert_ansi(*match.groups())
File "C:\Python32\lib\colorama\ansitowin32.py", line 154, in convert_ansi
self.call_win32(command, params)
File "C:\Python32\lib\colorama\ansitowin32.py", line 175, in call_win32
func(*args, **kwargs)
File "C:\Python32\lib\colorama\winterm.py", line 48, in fore
self.set_console(on_stderr=on_stderr)
File "C:\Python32\lib\colorama\winterm.py", line 68, in set_console
win32.SetConsoleTextAttribute(handle, attrs)
File "C:\Python32\lib\colorama\win32.py", line 66, in SetConsoleTextAttribute
assert success
AssertionError
关于哪里出了问题有什么想法吗?
I've recently started using Python 3.2 and have never attempted programming before. I copied the colorama folder to the lib directory in C:\Python32\lib and then made the following code in my attempt at a text-based adventure game:
import colorama
from colorama import Fore, Back, Style
colorama.init()
notedaction = "You have gained a SWORD AND SHIELD!"
uniqueskill = "strength"
if 'strength' in uniqueskill.lower():
time.sleep(3)
print('As you are a Warrior, I shall supply you with the most basic tools every Warrior needs.')
time.sleep(3)
print('A sword and shield.')
time.sleep(1)
print(Fore.RED + notedaction)
However, whenever I reach this section of code, I am given the following error:
File "<pyshell#10>", line 7, in <module>
print(Fore.RED + notedaction)
File "C:\Python32\lib\colorama\ansitowin32.py", line 34, in write
self.__convertor.write(text)
File "C:\Python32\lib\colorama\ansitowin32.py", line 115, in write
self.write_and_convert(text)
File "C:\Python32\lib\colorama\ansitowin32.py", line 140, in write_and_convert
self.convert_ansi(*match.groups())
File "C:\Python32\lib\colorama\ansitowin32.py", line 154, in convert_ansi
self.call_win32(command, params)
File "C:\Python32\lib\colorama\ansitowin32.py", line 175, in call_win32
func(*args, **kwargs)
File "C:\Python32\lib\colorama\winterm.py", line 48, in fore
self.set_console(on_stderr=on_stderr)
File "C:\Python32\lib\colorama\winterm.py", line 68, in set_console
win32.SetConsoleTextAttribute(handle, attrs)
File "C:\Python32\lib\colorama\win32.py", line 66, in SetConsoleTextAttribute
assert success
AssertionError
Any ideas on what is wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎是一个问题:colorama 0.1.18 with IDLE 在真正的 python 解释器中尝试。
It seems to be an issue of : colorama 0.1.18 with IDLE try in the real python interpretor.