beremiz

a2687c50362e
Parents 479b2c62d897
Children ef106a95bdf3
py_ext: fix CSV write: row and column append, error when going past the end of CSV
--- a/py_ext/py_ext.py Thu Dec 05 16:45:37 2024 +0100
+++ b/py_ext/py_ext.py Fri Dec 06 12:01:06 2024 +0100
@@ -63,6 +63,8 @@
try:
row = data[rowidx]
+ if not row and rowidx == len(data)-1:
+ raise IndexError
except IndexError:
return "#ROW_NOT_FOUND"
@@ -146,7 +148,7 @@
try:
if rowidx == len(data):
- row = [""]*len(data[0])
+ row = []
data.append(row)
else:
row = data[rowidx]
@@ -154,7 +156,12 @@
return "#ROW_NOT_FOUND"
try:
- row[colidx] = content
+ if rowidx > 0 and colidx >= len(data[0]):
+ raise IndexError
+ if colidx >= len(row):
+ row.extend([""] * (colidx - len(row)) + [content])
+ else:
+ row[colidx] = content
except IndexError:
return "#COL_NOT_FOUND"