save error with embedded python 2.5

E

Eric_Dexter

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))

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

thanks for any help in advance

I am using python 2.5 embeded into pycap.. the rest of the source is
available at
http://dexrowem.blogspot.com/2009/04/pycap-drum-machine-or-piano-roll-beta.html
if needed..
 
G

Gabriel Genellina

En Fri, 10 Apr 2009 09:40:11 -0300, (e-mail address removed)
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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,293
Messages
2,571,501
Members
48,189
Latest member
StaciLgf76

Latest Threads

Top