我試圖運行我的CMD腳本(它工作在IDLE罰款),但我得到這個錯誤:「返回codecs.charmap_encode」沒有特殊字符運行python腳本時
C:\Python34>rule90.py Traceback (most recent call last): File "C:\Python34\rule90.py", line 15, in <module> print(c) File "C:\Python34\lib\encodings\cp850.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-39: character maps to <undefined>
雖然我對Python的使用經驗有限,但我認爲我已經足夠了解這一點了。第19行簡單地爲linenew = str(''.join(lineA[numberneg:numberpos]))
,並且我加入的lineA包含以字符串形式加載的'0'和'1'。我有■和□字符,但它們應該是cmd中的默認字符,並且錯誤不在該行上。
任何幫助,將不勝感激!
lineA = ['0','0','0','0','0','0','1','0','0','0','0','0','0']
lineB = lineA[:]
lineC = lineA[:]
lineC = ['□' if x=='0' else '■' for x in lineC]
counth = 0
max_counth = len(lineA) - 2
countv = 0
max_countv = len(lineA)/2 - 1
while countv < max_countv:
number = 1
counth = 0
lineCstr = map(str, lineC)
c = ''.join(lineCstr)
print(c)
while counth < max_counth:
numberneg = number - 1
numberpos = number + 2
linenew = str(''.join(lineA[numberneg:numberpos]))
if linenew == str('110') or linenew == str('100') or linenew == str('011') or linenew == str('001'):
lineB[number] = '1'
lineC[number] = '■'
else:
lineB[number] = '0'
lineC[number] = '□'
number = number + 1
counth = counth + 1
lineA = lineB[:]
countv = countv + 1
input("Press Enter to continue...")
lineA
通常是一個較長的列表(25+數字),但對於節省空間的緣故,我縮短了它。
請發表您的腳本的完整代碼。 – NorthCat