Skip to content

Commit

Permalink
[perf-] Fallback to getattrdeep if len(row) < index
Browse files Browse the repository at this point in the history
Comes up with e.g. errors.csv where there are extra newlines and fields
in a subset of csv rows. Some rows will be shorter, and will result in
an IndexError when getitemdeep tries to grab their value for a later
column.

Builds on c324fca
  • Loading branch information
anjakefala committed Dec 2, 2023
1 parent 81221c4 commit 1618aed
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion visidata/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ def setattrdeep(obj, attr, val, getter=getattr, setter=setattr):

def getitemdeep(obj, k, *default):
if not isinstance(k, str):
return obj[k]
try:
return obj[k]
except IndexError:
pass
return getattrdeep(obj, k, *default, getter=getitem)

def setitemdeep(obj, k, val):
Expand Down

0 comments on commit 1618aed

Please # to comment.