En Fri, 10 Apr 2009 09:40:11 -0300, eric_dex...@msn.com <eric_dex...@msn.com> escribió:

I seem to be getting one extra value when I create my values with

for yy in range(1, maxy):
          for xx in range(1, maxx):
            count = count + 1
            #squaret.append[count]
            squaret.append( square(xx * 20, yy * 20))

yy goes from 1 to maxy-1, xx goes from 1 to maxx-1, there are (maxy-1)*(maxx-1) squares generated. Is that what you want?

and saving boxes with

if squaresave.state == '1':
          outfile = open('grid.dat','w')
          count = 0
          for s in squaret:
            count = count + 1
            outfile.write(s.state)
            outfile.write(' ')
            if count == maxy:
              outfile.write('\n')
              count = 0

Here, you're counting from 1 to maxy inclusive.

Why don't you use the same two-loop design both times? Or better, use a bidimensional data structure (like a list of lists, or the numpy library if you're mostly concerned with numbers).

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to