以下代码在IDLE中正确执行,但在控制台中返回错误。
import sys, math, string, time, os
from time import *
restart0 = True
while restart0:
def addDecimal():
print(".", end="\r")
breakout0 = False
invalidcommand0 = True
while invalidcommand0:
file = open("HighScores.txt","r+")
sleep(0.5)
print("\nWelcome to VACSecureServers™\n")
start = input("Would you like to start the program? ")
if start.lower() == "yes":
print("\n1. Display high scores\n2. Add a new high score\n3. Clear all high scores\n4. Quit")
option = input()
if option == "1":
print (file.read())
if os.stat("highscores.txt").st_size==0:
print("There are no highscores currently in the system, please return and input some.")
elif option == "2":
numberAppend = int(input("How many scores would you likes to add to the program? "))
for loop in range(numberAppend):
name = input("Enter the name of the user:" )
score = input("Enter a score: ")
file.write(name+","+score+","+strftime("%d/%m/%y %H:%M:%S\n"))
elif option == "3":
open("HighScores.txt", 'w').close()
print("Highscores resetting")
sleep(0.4)
addDecimal()
sleep(0.6)
addDecimal()
sleep(0.9)
addDecimal()
sleep(1.2)
print("Successfully reset!")
sleep(2)
elif option == "4":
sys.exit()
file.close()
这是我得到的错误:
Traceback (most recent call last):
File "E:\script.py", line 12, in <module>
print("\nWelcome to VACSecureServers™\n")
File: "C:\Python3\lib\encodings\cp437.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2122' in position 29: character maps to <undefined>
可能是什么问题?
答案 0 :(得分:0)
正是因为这条线
print("\nWelcome to VACSecureServers™\n")
您有一个™
符号。您的控制台可能无法显示它,但IDLE支持unicode字符。删除它,你的代码应该可以正常工作。