Тема: помилка в програмі
в мене така проблема програма запускається все добре але під час виконання видає помилку( програма працює з текстом)
оце видає консоль
''
Exception in thread Thread-1:
Traceback (most recent call last):
File "c:\users\alf\appdata\local\programs\python\python35-32\lib\threading.py", line 923, in _bootstrap_inner
File "c:\users\alf\appdata\local\programs\python\python35-32\lib\threading.py", line 871, in run
File "<string>", line 323, in th_menu_run
File "<string>", line 54, in __init__
File "<string>", line 59, in __get_data
File "c:\users\alf\appdata\local\programs\python\python35-32\lib\encodings\cp866.py", line 19, in encode
UnicodeEncodeError: 'charmap' codec can't encode character '\u0456' in position 12: character maps to <undefined>
Код самої програми
def connect_db():
conn = pymysql.connect("localhost", 'root', '1', "kursova_db", charset='utf8')
c = conn.cursor()
c.execute("select path from table_writer")
rows = c.fetchall()
path = []
for i in rows:
files = os.listdir(i[0] + "/")
for k in files:
path.append(i[0] + "/" + k)
return path
def conn_sql():
conn = sqlite3.connect("kursova_db")
c = conn.cursor()
c.execute("select path from table_writer")
rows = c.fetchall()
path = []
for i in rows:
files = os.listdir(i[0] + "/")
for k in files:
path.append(i[0] + "/" + k)
return path
def text_proc(file_name, lang="en"):
try:
text = open(file_name, encoding="utf8").read().lower()
except ZeroDivisionError:
showinfo("Error!", "Проблема з текстом! (текст містить нечитабельні символи)")
return
words = []
if lang == "en":
words = split("[^a-z'-]+", text)
if lang == "ua":
words = split("[^а-яіїґє'-]+", text)
if lang == "ru":
words = split("[^а-яё'-]+", text)
l = len(words)
i = 0
while i < l:
if words[i] == "" or words[i] == "-":
words.pop(i)
l -= 1
i += 1
return words
class TextsAnalis:
def __init__(self, path, m, lang="ua"):
self.data_text = {"l": [], "v": [], 'dv': [], 'l_ser': [], 'v_ser': []}
self.data_text_min_max = {'l_ser': [], 'v_ser': [], 'logl': [], 'log-v': []}
self.name_file = []
self.lang = lang
print("text_scan...")
self.__text_scan(path)
print("text_analis...")
self.__text_analis(m)
print("text_analis_log...")
self.__text_analis_log(m)
print("succesful_end")
def __text_scan(self, path):
words = text_proc(path[0], lang=self.lang)
data1 = []
data2 = []
data1.append(len(words))
data2.append(len(set(words)))
s = split('/', path[0])
name = []
name.append(s[len(s)-1])
for i in range(1, len(path)):
words = text_proc(path[i], lang=self.lang)
s = split('/', path[i])
name.append(s[len(s)-1])
data1.append(len(words))
data2.append(len(list(set(words))))
self.data_text['l'], self.data_text['v'], self.name_file = self.__sort1(data1, data2, name)
def __sort1(self, l1, l2, l3):
sorted1 = []
sorted2 = []
sorted3 = []
while len(l1):
m = min(l1)
i = l1.index(m)
sorted1.append(m)
sorted2.append(l2[i])
sorted3.append(l3[i])
l1.pop(i)
l2.pop(i)
l3.pop(i)
return sorted1, sorted2, sorted3
def __text_analis(self, m):
l = len(self.data_text['l'])
prom = int(l / m)
al = 0
bl = prom
for i in range(m):
ser1 = 0.0
ser2 = 0.0
ser_k2 = 0.0
for k in range(al, bl+1):
ser1 += self.data_text['l'][k]
ser2 += self.data_text['v'][k]
ser_k2 += self.data_text['v'][k]**2
self.data_text['l_ser'].append(ser1 / l)
self.data_text['v_ser'].append(ser2 / l)
self.data_text['dv'].append(math.fabs((ser_k2 / l) - ser2**2)**0.5)
al += prom
bl += prom
maxl = max(self.data_text['l'])
minl = min(self.data_text['l'])
prom = (maxl - minl) / m
al = minl
bl = minl + prom
while bl <= maxl:
ser1 = 0.0
ser2 = 0.0
for i in range(l):
if al <= self.data_text['l'][i] <= bl:
ser1 += self.data_text['l'][i]
ser2 += self.data_text['v'][i]
self.data_text_min_max['l_ser'].append(ser1 / l)
self.data_text_min_max['v_ser'].append(ser2 / l)
al += prom
bl += prom
def __text_analis_log(self, m):
logl = []
l = len(self.data_text['l'])
for i in range(l):
logl.append(math.log10(self.data_text['l'][i]))
maxl = max(logl)
minl = min(logl)
prom = (maxl - minl) / m
if prom == 0.0:
print("error prom = 0")
return
al = minl
bl = minl + prom
while bl <= maxl:
ser1 = 0.0
ser2 = 0.0
for i in range(l):
if al <= logl[i] <= bl:
ser1 += self.data_text['l'][i]
ser2 += self.data_text['v'][i]
self.data_text_min_max['logl'].append(ser1 / l)
self.data_text_min_max['logv'].append(ser2 / l)
al += prom
bl += prom
підкажіть в чому помилка?