2
我最近開始使用Python 3.2並從未嘗試過編程。我複製了COLORAMA文件夾到lib目錄C:\ Python32 \ lib中,然後在一個基於文本的冒險遊戲改變了我的嘗試下面的代碼:Python中的Colorama AssertionError 3.2
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
有什麼不對的想法?
http://code.google.com/p/colorama/issues/detail?id=19 – Apalala 2011-05-05 18:20:12
嘿。我是Colorama的作者。我不知道如何解決Colorama中的這個錯誤。它使得在IDLE內調用失敗的win32調用失敗。如果我只是停止在win32調用的返回值上執行「成功」的斷言,那也許會更有用。這會讓例外消失(但當然,我們仍然不會有任何彩色輸出,這是彩色的點)。想法,任何人? – 2011-06-19 18:59:20