Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #45382

Re: Question re: objects and square grids

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '16,': 0.03; 'parameters': 0.04; 'beginner': 0.05; '(except': 0.07; 'column': 0.07; 'friend.': 0.07; 'list?': 0.07; 'squares': 0.07; 'subject:Question': 0.07; 'function,': 0.09; 'grid': 0.09; 'learn,': 0.09; 'rows': 0.09; 'typed': 0.09; 'window?': 0.09; 'runs': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; '(0,': 0.16; '20)': 0.16; '4:35': 0.16; 'brackets': 0.16; 'ends,': 0.16; 'inclusive.': 0.16; 'normally,': 0.16; 'pygame': 0.16; 'received:74.208.4.195': 0.16; 'relevant,': 0.16; 'tuples,': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'wed,': 0.18; 'trying': 0.19; 'things.': 0.19; 'seems': 0.21; 'appears': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; "shouldn't": 0.24; 'sorry,': 0.24; 'looks': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '15,': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'wondering': 0.29; 'andrew': 0.30; "i'm": 0.30; 'code': 0.31; 'comments': 0.31; 'that.': 0.31; '13,': 0.31; 'are.': 0.31; 'implied': 0.31; 'them?': 0.31; 'stuff': 0.32; 'week.': 0.33; 'worked': 0.33; 'minimal': 0.33; 'moment': 0.34; "i'd": 0.34; 'could': 0.34; "can't": 0.35; 'no,': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; '14,': 0.36; 'returning': 0.36; 'right?': 0.36; 'words,': 0.36; 'doing': 0.36; 'should': 0.36; 'list': 0.37; 'being': 0.38; 'thank': 0.38; 'question,': 0.38; 'pm,': 0.38; 'expect': 0.39; '12,': 0.39; 'delete': 0.39; 'sure': 0.39; 'how': 0.40; 'read': 0.60; 'color': 0.61; 'lower': 0.61; 'utilize': 0.61; 'new': 0.61; 'entire': 0.61; 'range': 0.61; "you're": 0.61; 'show': 0.63; 'name': 0.63; 'become': 0.64; 'more': 0.64; '(that': 0.65; 'temporary': 0.65; 'received:74.208': 0.68; 'square': 0.74; 'upper': 0.74; 'perspective.': 0.84; 'tricky': 0.84; 'to:none': 0.92; 'besides,': 0.93; '2013': 0.98
Date Wed, 15 May 2013 20:17:48 -0400
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5
MIME-Version 1.0
CC python-list@python.org
Subject Re: Question re: objects and square grids
References <CAPp_YbVwiK1RBk_fLP32Kzv56GjYUf4TL=Ogzo5qsOKtrd8kGg@mail.gmail.com> <5193CC16.80304@davea.name> <5193E8C0.1060004@davea.name> <CAPp_YbVBm2444Ea-pUy2Zn2YbB1mKmDoasmNXp7DPAbs8Sra4g@mail.gmail.com> <CAPp_YbVk4NwSxSpVEASCk0w=1mPoRii+RjccnXNLP+8igf3H2g@mail.gmail.com>
In-Reply-To <CAPp_YbVk4NwSxSpVEASCk0w=1mPoRii+RjccnXNLP+8igf3H2g@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:hrFwFeYKvVEp6V2IqPzHPQBE0jlFLifo/QOjzcKsNFR eRHVGoe8cFlge6eEHTtrFBH7Ou99EpYUDqI3SkqKahKDnkh6mP ao6FJOe7Vrn6bPEltno5q03yTF066fCfUhGGEWRImQtcTZJz5D pFlaQbdhOSipFxL+Ig/w5fSSzb+Y0XE5HxKj82y0xT5i5XxqlK 6049LB9ziJ5SK/Eak9NRerrQwmraq/ZVohIcT5tj0gouNCQJgQ O7Z409qTKkOFhDMd/XVjrIHTkAK+tpPdwL1VBJ1rT6x1YiVcY6 3N9q9t4lusoH4FXZIbIx66eVURTvnkfMRRi6e0qsR3uG33Zbw= =
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1725.1368663489.3114.python-list@python.org> (permalink)
Lines 75
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1368663489 news.xs4all.nl 15945 [2001:888:2000:d::a6]:37137
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:45382

Show key headers only | View raw


Please put new comments AFTER the part you're quoting.  In other words, 
don't top-post.  Also please trim off the stuff that's no longer 
relevant, so people don't have to read through it all wondering where 
your implied comments are.

On 05/15/2013 06:48 PM, Andrew Bradley wrote:
> ok, now I have tested this more thoroughly, and it seems i can only do the
> grid[x][y] function up to grid[9][9], when i really should be able to be
> doing up to grid[10][20].

No, you shouldn't expect it to go to 10,20.  Remember I said that Python 
is zero-based.  So it goes from 0 to 9 inclusive, and from 0 to 19 
inclusive.  Upper left corner is grid[0][0], while lower right is 
grid[9][19].  Check to make sure that range works, which I think it will.


> What exactly is the function of this row_squares list?

It's a temporary to hold one row.  You could delete it after the outer 
loop ends, if you like. Normally, if this whole thing were inside a 
function, the variable would go away when the function ended, and you'd 
be returning the grid list only.

You could have avoided the separate name by doing some tricky syntax. 
But I'm trying to show you the clearest way of doing things from a 
beginner perspective.

>
>
>
> On Wed, May 15, 2013 at 4:35 PM, Andrew Bradley <abradley201@gmail.com>wrote:
>
>> Now I want to show you what I have written:
>>
>> row = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
>> column = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
>> 18, 19, 20)

No point in initializing them to tuples, since you're not going to use 
those.  Besides, in a moment row and column become ints, and this just 
confuses things.  The range() function below builds a temporary list 
which looks just like what you tediously typed in (except it's square 
brackets instead of round).

>> SQUARESIZE = 43
>>
>> grid = []
>> for row in range(10):
>>      row_squares = []
>>      for column in range(20):
>>          rect = Rect(12 + column * SQUARESIZE, 10 + row * SQUARESIZE,
>> SQUARESIZE, SQUARESIZE)
>>          row_squares.append(rect)
>>      grid.append(row_squares)
>>
>> It appears to be working (that is, the program still runs without
>> crashing).

Sorry, but that's no criteria.  Question is whether it's doing what you 
want.  Are the rows 20 across and are there 10 of them?  Do the values 
of each individual rect look right?  print is your friend.

>> So now, how can I utilize this new grid list? Thank you for the
>> help so far, I feel like the entire grid is now being worked out.
>> -Andrew
>>

That's a Pygame question, and I told you at the beginning, I can't 
really help with that.  I'd like to learn, but not this week.

Others - can you show some minimal code to use these grid parameters to 
color selected squares of the pygame window?

-- 
DaveA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Question re: objects and square grids Dave Angel <davea@davea.name> - 2013-05-15 20:17 -0400

csiph-web