Rows¶
-
class
dbapix.row.
Row
(raw, cur)[source]¶ A row in a query result.
Rows are tuples, but they have been augmented to behave like dicts:
for row in cur.execute('''SELECT foo FROM bar'''): print(row[0]) print(row['foo']) # The same thing.
Warning
Checking if a string is in a row via
'foo' in row
will check for both the key'foo'
and the value'foo'
! If you need to be explicit, then you should look in the various views:'foo' in row.keys() # or 'foo' in row.values()
-
Row.
__getitem__
(x)[source]¶ Get an item via index or key.
- Parameters
x – If an
int
, lookup by index. If astr
, lookup by name.- Raises
KeyError
orIndexError
Dict-like¶
-
Row.
get
(key, default=None)[source]¶ Get a value by column name.
- Parameters
key (str) – The name of the column.
default – What to return if the name doesn’t exist.
- Raises
KeyError
if the column doesn’t exist.
The next 3 have the appropriate behaviour in Python 2 or Python 3
The following are also defined as in Python 2: