I have been scripting with Python for a few years but I just recently decided to start using some OOP to make my life a bit easier. Although I've read many examples and some chapters and websites, some of the most rudimentary basics still elude me. Here is an example that is causing me trouble. I could use a nudge in the right direction.
What I'd like to do is define my data structure - which happens to be a complicated list of lists. I would like the class Superlist to allow me to access certain elements of the structure, so I don't have to keep looking up where each item is stored in the hierarchy. But I also still want access to the original list. I hope that makes sense. I assume I'm making some fundamental mistake in how I approach this problem, but I hope there is an easy way to have it explained to me.
Here is a very simplified example that illustrates the problem.
class Superlist(list):
def __init__(self, list):
self.a = list[1][0]
self.b = list[2][1]
somelist = [[1,2,3],[4,5,6],[7,8,9]]
somelist = Superlist(somelist)
>somelist.a # this works
>4
>somelist.b # this works
>7
>somelist # wait a minute - why can't I access the original list?
>[]
>somelist[0] # this should give me [1,2,3] - why doesn't it?
IndexError: list index out of range
I'd like to still be able to use somelist as a list structure. But it seems that once I define it as the Superlist, I lose that ability.