<div class="gmail_quote">On Fri, Sep 21, 2012 at 3:31 PM, Leo Degon <span dir="ltr"><<a href="mailto:existentialleo@gmail.com" target="_blank">existentialleo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

I'm trying to create a class where the main focus is creating a list whose elements are lists and the elements of those lists are collection of zeros and ones. I am trying to create functions to rotate the list ninety degrees, to reflect it. Having a few problems with the rotation.<div>


get TypeError: 'list' object is not callable<div><div><br></div></div></div><div><div>def pset(n):</div><div>    for i in n:</div><div>        print(i)</div><div>class board():</div><div>    def make(self,size):</div>


<div>        b=[]</div><div>        for i in range(size[0]):</div><div>            b.append([])</div><div>            for j in range(size[1]):</div><div>                b[i].append(0)</div><div>        return b</div><div>


<br></div><div>    def rotate(self,board,size):</div><div>        size[0],size[1]=size[1],size[0]</div><div>        new=board(size)</div><div>        lists=[]</div><div>        for j in range(size[1]):</div><div>            lists.append([])</div>


<div>            for i in range(size[0]).__reversed__():</div><div>                lists[j].append(board[i][j])</div><div>        for i in range(size[1]):</div><div>            for j in range(size[0]):</div><div>                new.board[i,j]=lists[i,j]</div>


<div>        return(new.board)</div><div>    def __init__(self,size):</div><div>        self.size=size</div><div>        self.board=self.make(size)        </div><div>y=[7,7]        </div><div>x=board(y)</div><div>pset(x.board)</div>


<div>x.board[0][0]=1</div><div>print()</div><div>pset(x.board)</div><div>print()</div><div>x.board=x.rotate(x.board,x.size)</div><div>pset(x.board)</div><div>print()</div></div><div><br></div></blockquote><div><br></div>

<div>Please always include a full traceback, it makes the error much more obvious. For example, running your code I get:</div><div><br></div><div><div>>>> </div><div>[0, 0, 0, 0, 0, 0, 0]</div><div>[0, 0, 0, 0, 0, 0, 0]</div>

<div>[0, 0, 0, 0, 0, 0, 0]</div><div>[0, 0, 0, 0, 0, 0, 0]</div><div>[0, 0, 0, 0, 0, 0, 0]</div><div>[0, 0, 0, 0, 0, 0, 0]</div><div>[0, 0, 0, 0, 0, 0, 0]</div><div>()</div><div>[1, 0, 0, 0, 0, 0, 0]</div><div>[0, 0, 0, 0, 0, 0, 0]</div>

<div>[0, 0, 0, 0, 0, 0, 0]</div><div>[0, 0, 0, 0, 0, 0, 0]</div><div>[0, 0, 0, 0, 0, 0, 0]</div><div>[0, 0, 0, 0, 0, 0, 0]</div><div>[0, 0, 0, 0, 0, 0, 0]</div><div>()</div><div><br></div><div>Traceback (most recent call last):</div>

<div>  File "C:/Users/hugo/Downloads/test.py", line 35, in <module></div><div>    x.board=x.rotate(x.board,x.size)</div><div>  File "C:/Users/hugo/Downloads/test.py", line 15, in rotate</div><div>

    new=board(size)</div><div>TypeError: 'list' object is not callable</div><div>>>> </div></div><div><br></div><div>This makes it fairly obvious what is going on. in the rotate function, you have an argument called board, and your class is also called board. You can't have the same name refer to two different things. What happens is that the argument "masks" the class, making it inaccessible.</div>

<div><br></div><div>I should also say it is very confusing to have a class called board with an attribute that is also called board. You should think about naming your variables more clearly to minimize confusion.</div><div>

<br></div><div>HTH,</div><div>Hugo</div></div>