Hi I have the following text file that I have uploaded here:
This data sits in a larger data set in a text file but I have just extracted the set of data I am interested in and uploaded it into a separate text file.
Data
Instead of reading these as strings I would like to read them as ints into a list. I have tried the following code but get an error. Any help would be much appreciated. Thanks!
This data sits in a larger data set in a text file but I have just extracted the set of data I am interested in and uploaded it into a separate text file.
Data
Instead of reading these as strings I would like to read them as ints into a list. I have tried the following code but get an error. Any help would be much appreciated. Thanks!
import tkinter as tk
from tkinter import filedialog
file_path = filedialog.askopenfilename()
print(file_path)
data = []
data2 = []
data3 = []
flag= False
with open(file_path,'r') as f:
for line in f:
if line.strip().startswith('*NSET, NSET=Nodes_Pushed_Back_IB'):
flag= True
elif line.strip().endswith('*NSET, NSET=Nodes_Pushed_Back_OB'):
flag= False #loop stops when condition is false i.e if false do nothing
elif flag: # as long as flag is true append
data.append([int(x) for x in line.strip().split(',')]) Get the following error:Error: ValueError: invalid literal for int() with base 10: ''I can't figure out how to get rid of the '' that is created when I strip() the lines.
