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:
parent
60f0584063
commit
5021f1f8cb
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user