|
|
@ -54,17 +54,14 @@ class Relation (object):
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, filename=""):
|
|
|
|
def __init__(self, filename=""):
|
|
|
|
self._readonly = False
|
|
|
|
self._readonly = False
|
|
|
|
|
|
|
|
self.content = set()
|
|
|
|
|
|
|
|
|
|
|
|
if len(filename) == 0: # Empty relation
|
|
|
|
if len(filename) == 0: # Empty relation
|
|
|
|
self.content = set()
|
|
|
|
|
|
|
|
self.header = Header([])
|
|
|
|
self.header = Header([])
|
|
|
|
return
|
|
|
|
return
|
|
|
|
with open(filename) as fp:
|
|
|
|
with open(filename) as fp:
|
|
|
|
reader = csv.reader(fp) # Creating a csv reader
|
|
|
|
reader = csv.reader(fp) # Creating a csv reader
|
|
|
|
self.header = Header(next(reader)) # read 1st line
|
|
|
|
self.header = Header(next(reader)) # read 1st line
|
|
|
|
self.content = set()
|
|
|
|
|
|
|
|
attributes = len(self.header)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
iterator = ((self.insert(i) for i in reader))
|
|
|
|
iterator = ((self.insert(i) for i in reader))
|
|
|
|
deque(iterator, maxlen=0)
|
|
|
|
deque(iterator, maxlen=0)
|
|
|
|
|
|
|
|
|
|
|
@ -88,17 +85,15 @@ class Relation (object):
|
|
|
|
format as defined in RFC4180.
|
|
|
|
format as defined in RFC4180.
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
fp = open(filename, 'w') # Opening file in write mode
|
|
|
|
with open(filename, 'w') as fp:
|
|
|
|
|
|
|
|
writer = csv.writer(fp) # Creating csv writer
|
|
|
|
|
|
|
|
|
|
|
|
writer = csv.writer(fp) # Creating csv writer
|
|
|
|
# It wants an iterable containing iterables
|
|
|
|
|
|
|
|
head = (self.header,)
|
|
|
|
|
|
|
|
writer.writerows(head)
|
|
|
|
|
|
|
|
|
|
|
|
# It wants an iterable containing iterables
|
|
|
|
# Writing content, already in the correct format
|
|
|
|
head = (self.header,)
|
|
|
|
writer.writerows(self.content)
|
|
|
|
writer.writerows(head)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Writing content, already in the correct format
|
|
|
|
|
|
|
|
writer.writerows(self.content)
|
|
|
|
|
|
|
|
fp.close() # Closing file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _rearrange(self, other):
|
|
|
|
def _rearrange(self, other):
|
|
|
|
'''If two relations share the same attributes in a different order, this method
|
|
|
|
'''If two relations share the same attributes in a different order, this method
|
|
|
|