work on csv logger class

master
polymurph 2 years ago
parent b11d73a67e
commit 2ac4fccbd8

5
.gitignore vendored

@ -10,3 +10,8 @@
*.op.raw
*.raw
#python
__pycache__/*
*.csv

@ -37,15 +37,3 @@ print(filepath)
addDatapoint(filepath,(10,10))
addDatapoints(filepath,((1, 2 ),(3, 4)))
'''
with open('test.csv', 'w', newline='' ) as file:
writer = csv.writer(file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer.writerow(header)
file.close()
addDatapoint('test.csv',(10,10))
addDatapoints('test.csv',((1,2),(3,4)))
'''

@ -0,0 +1,27 @@
import csv
class csvlogger(object):
def __init__(self, filename, filelocation, header):
self.filename = filename
self.filelocation = filelocation
self.header = header
self.filepath = filelocation + '\\' + filename + '.csv'
print(self.filepath)
with open(self.filepath, 'w', newline='' ) as f:
writer = csv.writer(f, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer.writerow(self.header)
f.close()
def addDatapoint(self, datapoint):
with open(self.filepath, 'a', newline='' ) as f:
writer = csv.writer(f, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer.writerow(datapoint)
f.close()
def addDatapoints(self, datapoints):
with open(self.filepath, 'a', newline='' ) as f:
writer = csv.writer(f, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer.writerows(datapoints)
f.close()

@ -0,0 +1,5 @@
class foo(object):
def __init__(self,txt):
print(txt)

@ -0,0 +1,8 @@
import os
import csvlogger as clg
import foo
logfile = clg.csvlogger('test', os.getcwd(), ('x', 'y'))
logfile.addDatapoint((10,10))
Loading…
Cancel
Save