You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Interprets the string contained in this CSVCell as a color code using the given encoding and returns a new CSVCell with that interpretation as its content.
125
+
E.g. if the CSVCell this function was called on contains '#4AA0C7' and 'CSVCell.DEC' is given as an encoding, a new CSVCell with content '4890823' is returned.
Initialize a new CSVRow object using the supplied column names and data. CSVRow objects are read-only by design.
146
+
If no data and no column names are supplied the resulting CSVRow object will evaluate to false in boolean expressions.
147
+
148
+
Access data within this CSVRow via the `get(key, default)` method or using `[<key: str>]`.
149
+
"""
150
+
ifnotcolumn_names:
151
+
column_names= []
152
+
ifnotdata:
153
+
data= []
154
+
155
+
iflen(column_names) !=len(data):
156
+
raiseValueError(
157
+
f"Could not build CSVRow from supplied column names and data; Number of supplied column names ({len(column_names)}) does not match number of supplied data entries ({len(data)}).")
158
+
159
+
self._data= {column_names[column_index]
160
+
: valueforcolumn_index, valueinenumerate(data)}
161
+
162
+
def__bool__(self):
163
+
"""
164
+
Allow for the use of CSVRow instances in if statements; If the CSVRow has no keys it is equivalent to `False`.
165
+
"""
166
+
returnlen(self._data.keys()) !=0
167
+
168
+
def__getitem__(self, key: str):
169
+
try:
170
+
returnself._data[key]
171
+
exceptKeyErroraske:
172
+
raiseValueError(
173
+
f"Failed to select column named '{ke.args[0]}' from CSVRow with columns {[keyforkeyinself._data]}.")
Initialize a new CSVRow object using the supplied column names and data. CSVRow objects are read-only by design.
57
-
If no data and no column names are supplied the resulting CSVRow object will evaluate to false in boolean expressions.
58
-
59
-
Access data within this CSVRow via the `get(key, default)` method or using `[<key: str>]`.
60
-
"""
61
-
ifnotcolumn_names:
62
-
column_names= []
63
-
ifnotdata:
64
-
data= []
65
-
66
-
iflen(column_names) !=len(data):
67
-
raiseValueError(
68
-
f"Could not build CSVRow from supplied column names and data; Number of supplied column names ({len(column_names)}) does not match number of supplied data entries ({len(data)}).")
0 commit comments