Hi, sorry about the long length of code.
However, I feel I need to show in full to describe what I am about.
The code below works. However, surely there is a more elegant way.
I tried to use a for loop. But had no success.
I don't really want to type out line by line.
I may need to break the one function in to two functions, but for now.
Thanks,
However, I feel I need to show in full to describe what I am about.
The code below works. However, surely there is a more elegant way.
I tried to use a for loop. But had no success.
I don't really want to type out line by line.
I may need to break the one function in to two functions, but for now.
Thanks,
import struct import time import csv # Get Data out of Binary File def readdata(filename,i): '''Read data from a file. Data count is in the header''' with open(filename, "rb") as file: buffer = file.read(20) size, variation, objectType, pointIndex, startTime, sampleRate, count = struct.unpack('>IBBHiII', buffer) print(size, variation, objectType, startTime, sampleRate, count) count = count + 20 buffer = file.read(4 * (count)) values = struct.unpack(f'={count}f', buffer) return values[i] print(readdata('XXXXXXX',6)) #numbers = [6, 7, 8, 9, 10, 11] #for val in numbers: # Create and Write to CSV File with open('XXXXXXX.csv', 'w', newline='') as file: writer = csv.writer(file) writer.writerow(["Blank1", "DateTime", "Blank2", readdata('XXXXXXX',6)]) writer.writerow(["Blank1", "DateTime", "Blank2", readdata('XXXXXXX',7)]) writer.writerow(["Blank1", "DateTime", "Blank2", readdata('XXXXXXX',8)]) writer.writerow(["Blank1", "DateTime", "Blank2", readdata('XXXXXXX',9)]) writer.writerow(["Blank1", "DateTime", "Blank2", readdata('XXXXXXX',10)]) writer.writerow(["Blank1", "DateTime", "Blank2", readdata('XXXXXXX',11)]) writer.writerow(["Blank1", "DateTime", "Blank2", readdata('XXXXXXX',12)])