I want to write a little python script to plot some .dat files. For that I need to process the files first. The .dat file looks like this:
(Real64
(numDims 1)
(size 513)
(data
[ 90.0282291905089 90.94377050431068 92.31708247501335 93.38521400778211 94.60593575951782 95.67406729228657 97.04737926298925 97.96292057679104 ...]
)
)
I want to delete the text parts and the 'normal' brackets. I just need the data in between [.....].
I tried something like this:
from Tkinter import Tk
from tkFileDialog import askopenfilename
# just a small GUI to get the file
Tk().withdraw()
filename = askopenfilename()
import numpy as np
with open(filename) as f:
temp = f.readlines(5) #this is the line in the .dat file
for i in range(len(temp)-1):
if type(temp[i]) == str:
del temp[i]
However, this always leads to an 'index of out bounds'. Help would be much appreciated.