Код: Выделить всё
class Logs:
def __init__(self, archive_file):
self.files = {'audit.log': b'1\t2024-08-04 12:00:12\tuser\tmessage\n2\t2024-08-04 12:00:13\tuser\tmessage2\n_etc.',
'system.log': b'1\t2024-08-04 12:00:12\tuser\tmessage\n2\t2024-08-04 12:00:13\tuser\tmessage\n_etc'}
Код: Выделить всё
class logsNotebook(ttk.Notebook):
def __init__(self, data, parent, ui):
super().__init__(parent)
if ui.logs_button.cget("style") != "AccentButton":
ui.logs_button.configure(style="AccentButton")
ui.general_button.configure(style='')
ui.network_button.configure(style='')
ui.config_button.configure(style='')
tab1 = Frame(self)
tab2 = Frame(self)
self.add(tab1, text="System Log")
self.add(tab2, text="Audit Log")
self.pack(expand=True, fill="both")
### System Log ###############################################################
file = data.files['system.log'].decode('utf-8')
lines = []
for line in file.splitlines():
lines.append(line)
print(len(lines))
print(lines[-1])
Файлы находятся в правильном месте, код tkinter для кнопок и блокнота работает, а данные успешно считываются в память в основная программа. Фактически, если я просто читаю файл в начале урока, он работает нормально. Если я заменю раздел системного журнала следующим:
Код: Выделить всё
with open("system.log", "r") as f:
lines = f.readlines()
print(len(lines))
print(lines[-1])
Если я напишу программу test.py, которая делает то же самое, она тоже успешно работает:
Код: Выделить всё
import Logs
my_path = 'C:/Scripts/Python/testdata/system.log'
data = logs(my_path) #In the real code this is just grabbing the dictionary above
file = data.files['system.log'].decode('utf-8')
lines = []
for line in file.splitlines():
lines.append(line)
print(len(lines))
print(lines[-1])
Подробнее здесь: https://stackoverflow.com/questions/788 ... en-classes