-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTable.py
More file actions
42 lines (26 loc) · 834 Bytes
/
Table.py
File metadata and controls
42 lines (26 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'''
Class representing a database table for
CS 457 Final Project
Daniel Klein
Spring 2015
'''
class Table(object):
def __init__(self, table_name):
self.name = table_name
self.column_names = []
# each row is keyed on TS, contains dict containing
# col name-data val pairs
self.rows = {}
def add_column_name(self, col):
if (col not in self.column_names):
self.column_names.append(col)
return
# end add_column_name
def add_value(self, key, col_name, value):
if (col_name not in self.column_names):
raise Exception("Invalid column name.")
if (key not in self.rows):
self.rows[key] = {}
self.rows[key][col_name] = value
return
# end add_value