Re: [Tutor] New to this list ....

2012-03-30 Thread Emile van Sebille
On 3/30/2012 2:41 PM Barry Drake said... On 30/03/12 19:18, Cranky Frankie wrote: Here's what you need - he starts simple and winds up with some nice games: http://www.amazon.com/Python-Programming-Absolute-Beginner-Edition/dp/1435455002/ref=sr_1_6?ie=UTF8&qid=1333131438&sr=8-6 If you have

Re: [Tutor] New to this list ....

2012-03-30 Thread Barry Drake
On 30/03/12 19:18, Cranky Frankie wrote: Here's what you need - he starts simple and winds up with some nice games: http://www.amazon.com/Python-Programming-Absolute-Beginner-Edition/dp/1435455002/ref=sr_1_6?ie=UTF8&qid=1333131438&sr=8-6 Wow! I found an e-book copy online and got it. Looks go

[Tutor] New to this list ....

2012-03-30 Thread Cranky Frankie
Message: 1 Date: Fri, 30 Mar 2012 15:04:09 +0100 Barry Drake wrote: << I'm getting a Raspberry-pi for our local Junior school and am starting to learn Python so I can show the year five and year six kids how to write simple games.>> Here's what you need - he starts simple and winds up with some

Re: [Tutor] New to this list ....

2012-03-30 Thread Russel Winder
Barry, On Fri, 2012-03-30 at 18:27 +0100, Barry Drake wrote: > On 30/03/12 17:58, Mark Lawrence wrote: > > The recipe here > > http://code.activestate.com/recipes/410692-readable-switch-construction-without-lambdas-or-di/ > > > > > > refers to several other recipes which you might want to take a

Re: [Tutor] New to this list ....

2012-03-30 Thread Emile van Sebille
On 3/30/2012 10:56 AM Prasad, Ramit said... Lists are mutable objects. When you pass a list to a function you bind a name in the functions namespace to the list object. Every name binding to that object will have the ability to modify the list. If you want to modify the list but not change it f

Re: [Tutor] New to this list ....

2012-03-30 Thread Prasad, Ramit
[snip] >I'm used to c > variables going out of scope once you leave the called function. I > imagine if you want to leave the variables unchanged, you have to > re-assign them inside the function. [snip] Lists are mutable objects. When you pass a list to a function you bind a name in the functi

Re: [Tutor] New to this list ....

2012-03-30 Thread Barry Drake
On 30/03/12 17:22, Prasad, Ramit wrote: Unlike C, the parenthesis in if statements and returns are not necessary. Furthermore, the way Python binds names means that modifying the list in getflags modifies it in the callee. No need to return and reassign results. This is lovely. It's so much

Re: [Tutor] New to this list ....

2012-03-30 Thread Barry Drake
On 30/03/12 17:58, Mark Lawrence wrote: The recipe here http://code.activestate.com/recipes/410692-readable-switch-construction-without-lambdas-or-di/ refers to several other recipes which you might want to take a look at, sorry I meant to mention this earlier. Oh, that's neat. Not worth

Re: [Tutor] New to this list ....

2012-03-30 Thread Mark Lawrence
On 30/03/2012 15:04, Barry Drake wrote: One of the few c things I miss is the switch/case statement. if and elif in it's place is a bit cumbersome. Still, it works. The recipe here http://code.activestate.com/recipes/410692-readable-switch-construction-without-lambdas-or-di/ refers to severa

Re: [Tutor] New to this list ....

2012-03-30 Thread Prasad, Ramit
> [...] > > C switch is just a different way of doing an if/elif tree, I do not > > really see any real difference. Although, if there is you can feel free > > to enlighten me. :) > [...] > > 'fraid not -- though it depends on which compiler and how many cases. > For 3 or more cases compilers will

Re: [Tutor] New to this list ....

2012-03-30 Thread Russel Winder
Ramit, On Fri, 2012-03-30 at 16:22 +, Prasad, Ramit wrote: [...] > C switch is just a different way of doing an if/elif tree, I do not > really see any real difference. Although, if there is you can feel free > to enlighten me. :) [...] 'fraid not -- though it depends on which compiler and

Re: [Tutor] New to this list ....

2012-03-30 Thread Prasad, Ramit
> Furthermore, the way Python binds names means that modifying the list > in getflags modifies it in the callee. No need to return and reassign > results. I correct myself. It has nothing to do with name binding, but entirely to do with Python's object model. Ramit Ramit Prasad | JPMorgan Chas

Re: [Tutor] New to this list ....

2012-03-30 Thread Prasad, Ramit
> > Hi there I've just joined this list and thought I'd introduce myself. Welcome! > > correct = 0 > > match = 0 > > wrong = 0 > > results = [correct, match, wrong] > > > > results = getflag(flag_1, results) > > results = getflag(flag_2, results) > > results = get

Re: [Tutor] New to this list ....

2012-03-30 Thread Peter Otten
Barry Drake wrote: > On 30/03/12 16:19, Evert Rol wrote: >> Not sure. In the sense that you can "optimise" (refactor) it in the same >> way you could do with C. Eg: results = [0, 0, 0] >> flags = [0, 1, 2, 3] >> for flag in flags: >> results = getflag(flag, results) >> > > That's exactly wha

Re: [Tutor] New to this list ....

2012-03-30 Thread Russel Winder
Barry, On Fri, 2012-03-30 at 16:42 +0100, Barry Drake wrote: [...] > def getflag(thisflag, results): > if (thisflag == 2): > results[0] += 1 > elif (thisflag == 1): > results[1] += 1 > elif (thisflag == 0): > results[2] += 1 > return(results) Two tho

Re: [Tutor] New to this list ....

2012-03-30 Thread Asokan Pichai
On Fri, Mar 30, 2012 at 9:12 PM, Barry Drake wrote: > On 30/03/12 16:19, Evert Rol wrote: >> >> Not sure. In the sense that you can "optimise" (refactor) it in the same >> way you could do with C. Eg: >> results = [0, 0, 0] >> flags = [0, 1, 2, 3] >> for flag in flags: >>     results = getflag(fla

Re: [Tutor] New to this list ....

2012-03-30 Thread Barry Drake
On 30/03/12 16:19, Evert Rol wrote: Not sure. In the sense that you can "optimise" (refactor) it in the same way you could do with C. Eg: results = [0, 0, 0] flags = [0, 1, 2, 3] for flag in flags: results = getflag(flag, results) That's exactly what I hoped for. I hadn't realised I can

Re: [Tutor] New to this list ....

2012-03-30 Thread Mark Lawrence
On 30/03/2012 15:13, Barry Drake wrote: On 30/03/12 15:04, Barry Drake wrote: One of the things I wanted to do is to use a four integer array to get four integers returned from a function. I ended up using what I think is a list. (I'm not really sure of the datatypes yet). This is what I Pleas

Re: [Tutor] New to this list ....

2012-03-30 Thread Evert Rol
Hi and welcome Barry, > One of the things I wanted to do is to use a four integer array to get four > integers returned from a function. I ended up using what I think is a list. > (I'm not really sure of the datatypes yet). This is what I did, and it > works, but looks very inelegant to me:

Re: [Tutor] New to this list ....

2012-03-30 Thread Barry Drake
On 30/03/12 15:04, Barry Drake wrote: One of the things I wanted to do is to use a four integer array to get four integers returned from a function. I ended up using what I think is a list. (I'm not really sure of the datatypes yet). This is what I did, and it works, but looks very inelegant

[Tutor] New to this list ....

2012-03-30 Thread Barry Drake
Hi there I've just joined this list and thought I'd introduce myself. I used to be fairly competent in c but never made the grade to c++. I've done very little programming in the last couple of years or so. I'm getting a Raspberry-pi for our local Junior school and am starting to learn