From b3ba8cd8902d17012479ee6c0e6e6699882258af Mon Sep 17 00:00:00 2001 From: jacques Grelet <Jacques.Grelet@ird.fr> Date: Sun, 10 Mar 2019 17:18:14 +0000 Subject: [PATCH] create roscop module (objetct) update gitignore --- .gitignore | 1 + code_roscop.csv => roscop/code_roscop.csv | 0 roscop/roscop.py | 35 +++++++++++++++++++++++ 3 files changed, 36 insertions(+) rename code_roscop.csv => roscop/code_roscop.csv (100%) create mode 100644 roscop/roscop.py diff --git a/.gitignore b/.gitignore index c6039a2..9beac58 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ *.nc *.xml *.stackdump +__pycache__ diff --git a/code_roscop.csv b/roscop/code_roscop.csv similarity index 100% rename from code_roscop.csv rename to roscop/code_roscop.csv diff --git a/roscop/roscop.py b/roscop/roscop.py new file mode 100644 index 0000000..f6d6206 --- /dev/null +++ b/roscop/roscop.py @@ -0,0 +1,35 @@ +""" +code roscop +""" + +import csv, shelve,sys + +# class roscop +# ------------ +class Roscop: + + # constructor with values by default + def __init__(self, file): + self.file = file + + # call by print() + def __repr__(self): + return "class Roscop, file: {}".format(self.file) + + # read code roscop file + def read(self): + print("Code roscop file: %s" % self.file) + with open(self.file, 'rt') as f: + reader = csv.DictReader(f, delimiter=';') + for row in reader: + print("%s : %s : %s : %s : %s" % (row['key'], row['long_name'], + row['standard_name'], row['units'], row['format'])) + return + +# for testing in standalone context +# --------------------------------- +if __name__ == "__main__": + from roscop import Roscop + r = Roscop("code_roscop.csv") + r.read() + print(r) \ No newline at end of file -- GitLab