save error with embedded python 2.5
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sun Apr 12 17:29:50 EDT 2009
En Fri, 10 Apr 2009 09:40:11 -0300, Eric_Dexter at msn.com
<Eric_Dexter at 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
More information about the Python-list
mailing list