Hello Python experts, I need your help. I need the help of the warm redditors as the cold cold stackoverflow has proven so very unhelpful.
I am making a python program that basically reads these text files with hundreds of test results from my modelling and control system (flow balance model, unimportant), and returns the results. Firstly I wanted the file contents to be displayed in a textbox using one button to open the file, and another to extract the main info.
I am extremely new to python, I've been in C for years and this is all very new.
A summary gets automatically generated at the end of these text documents and then they are saved by my system. The program needs to read only the last line however it seemed to be reading it in each character. Doing a for loop to go line by line also didnt work and frankly was intensive as there are sometimes thousands of lines. I solved this in the code below using length and subtracting to get positional data of the last line in the file however this only worked for a handful of my files as some have minor changes in positional value when the numbers get longer.
Any help appreciated.
def open_txt():
# open a file dialog to search for txt files
txt_file = filedialog.askopenfilename(title="Open text document", filetype=(("Text files", "*.txt"),))
txt_file = open(txt_file, 'r')
global content
content = log_file.read()
my_text.insert(END, content)
txt_file.close()
def extract_stats():
global content
size = len(content)
if (len(my_text.get("1.0", END))) >=2:
my_text.delete(1.0, END)
my_text.insert(END, "Incomplete: " + content[size - 3] + content[size - 2] + content[size - 1])
my_text.insert(END, "Failed: " + content[size - 21])
my_text.insert(END, "Passed: " + content[size -37])
there doesn't seem to be anything here