diff options
Diffstat (limited to 'analyze.py')
-rw-r--r-- | analyze.py | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -43,6 +43,7 @@ import json, os, sys # Solve UnicodeDecodeError - https://blog.csdn.net/blmoistawinde/article/details/87717065
import _locale
+import codecs
_locale._getdefaultlocale = (lambda *args: ['zh_CN', 'utf8'])
@@ -54,6 +55,7 @@ def get_task_information(fname): def get_student_information(fname):
result = []
+
with open(fname) as f:
for line in f:
line = line.strip()
@@ -78,6 +80,14 @@ def get_max_score(d): def get_student_number(fname):
d = {}
+
+ # If a file has BOM (Byte Order Marker) charater, stop.
+ with open(fname, 'r+b') as f:
+ s = f.read()
+ if s.startswith(codecs.BOM_UTF8):
+ print('\nERROR: The file %s contains BOM character. Remove that first.' % (fname))
+ sys.exit()
+
f = open(fname)
for line in f:
line = line.strip()
|