Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Array
#1
Hi, I want to print the sample values to a csv file.
The code below does create a file and prints to it.

Though I want the "value" part of the writerow to an actual sample value.

Blank1, DateTime, Blank2, SampleValue1
Blank1, DateTime, Blank2, SampleValue2
Blank1, DateTime, Blank2, SampleValue3 etc till end of sample value's

Would I use an array or list and step through a for loop.
Thanks,

import struct
import time
import csv
     
# Get Data out of Binary File
def readdata(filename):
    '''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)
          
        buffer = file.read(4 * count)
        values = struct.unpack(f'={count}I', buffer)
        return values
 
print(readdata('XXXXXXXXXXX'))
 
# Create and Write to CSV File
with open('XXXXXXXXXXX.csv', 'w', newline='') as file:
    writer = csv.writer(file)
    writer.writerow(["Blank1", "DateTime", "Blank2", "Value"])
Reply


Messages In This Thread
Array - by Aussie - Sep-03-2020, 04:06 AM
RE: Array - by deanhystad - Sep-03-2020, 04:16 AM
RE: Array - by Aussie - Sep-03-2020, 09:56 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020