diff --git a/.gitignore b/.gitignore index 9923b06..0d7273c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,8 @@ *.op.raw *.raw +#python +__pycache__/* +*.csv + + diff --git a/python/CSV_writer/csv_writer.py b/python/CSV_writer/csv_writer.py index a18aaad..190fad1 100644 --- a/python/CSV_writer/csv_writer.py +++ b/python/CSV_writer/csv_writer.py @@ -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))) - -''' \ No newline at end of file diff --git a/python/CSV_writer/csvlogger.py b/python/CSV_writer/csvlogger.py new file mode 100644 index 0000000..0d16274 --- /dev/null +++ b/python/CSV_writer/csvlogger.py @@ -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() \ No newline at end of file diff --git a/python/CSV_writer/foo.py b/python/CSV_writer/foo.py new file mode 100644 index 0000000..ca9a197 --- /dev/null +++ b/python/CSV_writer/foo.py @@ -0,0 +1,5 @@ + + +class foo(object): + def __init__(self,txt): + print(txt) \ No newline at end of file diff --git a/python/CSV_writer/test.py b/python/CSV_writer/test.py new file mode 100644 index 0000000..d6e2efd --- /dev/null +++ b/python/CSV_writer/test.py @@ -0,0 +1,8 @@ +import os +import csvlogger as clg +import foo + +logfile = clg.csvlogger('test', os.getcwd(), ('x', 'y')) + +logfile.addDatapoint((10,10)) +