Use the insert() method to load files

In this way, checks are performed automatically on every tuple
and code is simplified.

This should make it safer to raise exceptions on files that are
not relations.
This commit is contained in:
Salvo 'LtWorf' Tomaselli 2015-06-07 14:03:24 +02:00
parent 60f0584063
commit 5021f1f8cb

View File

@ -22,6 +22,7 @@
import csv
from itertools import chain, repeat
from collections import deque
from relational.rtypes import *
@ -47,19 +48,14 @@ class relation (object):
self.content = set()
self.header = header([])
return
# Opening file
fp = open(filename)
with open(filename) as fp:
reader = csv.reader(fp) # Creating a csv reader
self.header = header(next(reader)) # read 1st line
self.content = set()
attributes = len(self.header)
for i in reader: # Iterating rows
self.content.add(tuple(map (rstring, i)))
# Closing file
fp.close()
iterator = ((self.insert(i) for i in reader))
deque(iterator, maxlen=0)
def _make_writable(self):
'''If this relation is marked as readonly, this