welcom ! Handel home

2016年5月18日 星期三

Python OO copy and deepcopy 9x9 Pad by SUDO test code

import copy

class suitem:
    def __init__(self):
        dd = [1,2,3,4,5,6,7,8,9]
        ddx = []
        self.set = ['x']*9*9
#        self.data = copy.deepcopy(dd)*9*9
        for i in range(9):
            for j in range(9):
                ddx.append(copy.deepcopy(dd))
        self.data = ddx

    def showset(self):
        for i in range(9):
            print ">>[",
            for j in range(9):
                print self.set[i*9+j],
            print "]<<"

    def showdata(self):
        for i in range(9):
            print ">>[",
            for j in range(9):
                print self.data[i*9+j],
            print "]<<"
           
if __name__ == '__main__':
    sett = suitem()


    a = copy.copy(sett)
    b = copy.deepcopy(sett)

   
    sett.set[0] ='1'
    print "=== other ==="
    sett.showset()
    print "=== other ==="
    a.showset()
    print "=== other ==="
    b.showset()
    print "=== end   ==="
   

沒有留言: