Skip to content
Snippets Groups Projects
Commit 0e9df494 authored by jacques Grelet's avatar jacques Grelet
Browse files

remove class db, add hash in class Roscop

comment import Roscop
parent 24e21842
No related branches found
No related tags found
No related merge requests found
...@@ -7,11 +7,6 @@ import shelve ...@@ -7,11 +7,6 @@ import shelve
import sys import sys
class db:
def __setattr__(self, name, value):
self.__dict__[name] = value
# class roscop # class roscop
# ------------ # ------------
...@@ -25,32 +20,21 @@ class Roscop: ...@@ -25,32 +20,21 @@ class Roscop:
# call by print() # call by print()
def __str__(self): def __str__(self):
# print("%s:" % row[key], end='')
# print()
return 'Class Roscop, file: %s, size = %d' % (self.file, len(self.hash)) return 'Class Roscop, file: %s, size = %d' % (self.file, len(self.hash))
def disp(self, theKey): def disp(self, theKey):
#(a,b) = self.hash[theKey].items() print(self.hash[theKey])
print(self.hash.items())
# for attr, value in d.__dict__.items():
#print(attr, value)
# print(d.__dict__)
# read code roscop file # read code roscop file
def read(self): def read(self):
d = db()
with open(self.file, 'rt') as f: with open(self.file, 'rt') as f:
reader = csv.DictReader(f, delimiter=';') reader = csv.DictReader(f, delimiter=';')
#print("%s" % (reader.fieldnames))
for key in reader.fieldnames:
d.key = key
for row in reader: for row in reader:
theKey = row[reader.fieldnames[0]] theKey = row[reader.fieldnames[0]]
for k in reader.fieldnames: # for k in reader.fieldnames:
d.k = row[k] # print(k, row[k])
self.hash[theKey] = d self.hash[theKey] = row
#print("Key : %s" % theKey)
return return
...@@ -58,7 +42,7 @@ class Roscop: ...@@ -58,7 +42,7 @@ class Roscop:
# for testing in standalone context # for testing in standalone context
# --------------------------------- # ---------------------------------
if __name__ == "__main__": if __name__ == "__main__":
from roscop import Roscop #from roscop import Roscop
r = Roscop("code_roscop.csv") r = Roscop("code_roscop.csv")
r.read() r.read()
print(r) print(r)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment