Skip to content

Instantly share code, notes, and snippets.

@feriat
Last active August 29, 2015 14:13
Show Gist options
  • Save feriat/3210ff8fdca3a40e4fed to your computer and use it in GitHub Desktop.
Save feriat/3210ff8fdca3a40e4fed to your computer and use it in GitHub Desktop.
DataJoy mini bug with __builtin__
class llist(__builtin__.list):
"""Special list for Ordered Models. Element -1 is -Inf, Final element is Inf.
--------------------------------------------------------
EXAMPLE:
x = llist([12.,14,2.2])
x[1]
>>>14
x[-1], x[3]
>>>(-inf, inf)
x[-2]
>>>IndexError: Not supported index -2 was called.
"""
def __getitem__(self, l):
if l == -1:
return -np.inf
elif l == len(self):
return np.inf
elif l < -1 or l > len(self):
raise IndexError, "Not supported index %i was called."%l
else:
return super(llist,self).__getitem__(l)
Traceback (most recent call last):
File "CNOP.py", line 13, in <module>
class llist(__builtin__.list):
NameError: name '__builtin__' is not defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment