fix the write file compatibility on windows platform.

master
Max 2023-07-17 18:17:33 +08:00 committed by GitHub
parent ef9585ce8a
commit 940f1ddebf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 14 deletions

View File

@ -28,7 +28,7 @@ import asyncio
import tornado import tornado
from tornado.web import Application from tornado.web import Application
CONST_APP_VERSION = "MaxBot (2023.07.08)" CONST_APP_VERSION = "MaxBot (2023.07.09)"
CONST_MAXBOT_QUESTION_FILE = "MAXBOT_QUESTION.txt" CONST_MAXBOT_QUESTION_FILE = "MAXBOT_QUESTION.txt"
@ -227,9 +227,14 @@ def web_server():
def preview_question_text_file(): def preview_question_text_file():
if os.path.exists(CONST_MAXBOT_QUESTION_FILE): if os.path.exists(CONST_MAXBOT_QUESTION_FILE):
question_text = "" infile = None
with open(CONST_MAXBOT_QUESTION_FILE, "r") as text_file: if platform.system() == 'Windows':
question_text = text_file.readline() infile = open(CONST_MAXBOT_QUESTION_FILE, 'r', encoding='UTF-8')
else:
infile = open(CONST_MAXBOT_QUESTION_FILE, 'r')
if not infile is None:
question_text = infile.readline()
global txt_question global txt_question
try: try: