Title: Negative Array Index not Yielding "Index Out Of Bounds"
Type: behavior Stage: resolved
Components: Versions:
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: NNN, zach.ware
Priority: normal Keywords:

Created on 2019-12-19 04:13 by NNN, last changed 2019-12-19 05:24 by NNN. This issue is now closed.

Messages (3)
msg358655 - (view) Author: (NNN) Date: 2019-12-19 04:13
Created an 2D array:
bigFloorLayout = []       
        bigFloorLayout=[[False for row in range(0,45] for col in range(0,70]

for y in range (offsetY, storageY + offsetY):
            for x in range (offsetX, storageX + offsetX):
                bigFloorLayout[x][y] = True

Offset is a negative number, and thus accessing bigFloorLayout[0][-1], which did not yield "Index out of Bounds" as it should.
This is in Blender 2.81, so I have no idea what version of python it is.
msg358656 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2019-12-19 04:33
`-1` is not out of bounds unless the array is empty; negative indices count from the other end:

>>> a = list("some array")
>>> a
['s', 'o', 'm', 'e', ' ', 'a', 'r', 'r', 'a', 'y']
>>> a[-1]
>>> b = []
>>> b[-1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range

See about halfway down this [1] section; look for "Indices may also be negative".

msg358657 - (view) Author: (NNN) Date: 2019-12-19 05:24
Ahh, thanks.
Date User Action Args
2019-12-19 05:24:09NNNsetmessages: + msg358657
2019-12-19 04:33:04zach.waresetstatus: open -> closed

nosy: + zach.ware
messages: + msg358656

resolution: not a bug
stage: resolved
2019-12-19 04:13:20NNNcreate