Re: [Tutor] List of ints

2015-03-03 Thread Alan Gauld
On 03/03/15 06:50, Phil wrote: I'd like to set up a two dimensional list of counters as follows; count = [ [0], [0], [0] ] And then increment the first counter as follows; count [0] += 1 Are you trying to increment the zero to make it 1? Or are you trying to add a new value, 1, to the first

Re: [Tutor] List of ints

2015-03-03 Thread Danny Yoo
On Mon, Mar 2, 2015 at 10:50 PM, Phil wrote: > Thank you for reading this. > Python 3 under Linux. > > I'd like to set up a two dimensional list of counters as follows; > > count = [ > [0], > [0], > [0] > ] > Can you explain why the list is two-dimensi

[Tutor] (no subject)

2015-03-03 Thread chelseysp
don't understand why these execute different things… total=total+10 >>> total=total+25 >>> total=total+25 >>> average=total/3 >>> total 110 >>> average 36.664 and total=0 >>> total=total+10 >>> total=total+25 >>> total=total+25 >>> average=total/3 >>> average 20.0

Re: [Tutor] How to test a class in python?

2015-03-03 Thread Marcos Almeida Azevedo
On Mon, Mar 2, 2015 at 12:41 PM, Danny Yoo wrote: > On Sun, Mar 1, 2015 at 11:41 AM, Alan Gauld > wrote: > > On 01/03/15 16:19, Fatimah Taghdi wrote: > >> > >> Hello I was wondering how to test a class in python is it the same way > as > >> testing a function ? > > > Depending on the design of t

Re: [Tutor] (no subject)

2015-03-03 Thread Danny Yoo
On Mon, Mar 2, 2015 at 10:22 PM, wrote: > > don't understand why these execute different things… > > > > > total=total+10 total=total+25 total=total+25 average=total/3 total > 110 average > 36.664 In your first case, what's the value of 'total' *before* all

[Tutor] codecs.open vs io.open

2015-03-03 Thread Albert-Jan Roskam
Hi, Is there in a (use case) difference between codecs.open and io.open? What is the difference? A small difference that I just discovered is that codecs.open(somefile).read() returns a bytestring if no encoding is specified, but a unicode string if an encoding is specified. io.open always retu

Re: [Tutor] How to test a class in python?

2015-03-03 Thread Mark Lawrence
On 03/03/2015 06:25, Marcos Almeida Azevedo wrote: On Mon, Mar 2, 2015 at 12:41 PM, Danny Yoo wrote: On Sun, Mar 1, 2015 at 11:41 AM, Alan Gauld wrote: On 01/03/15 16:19, Fatimah Taghdi wrote: Hello I was wondering how to test a class in python is it the same way as testing a function ?

Re: [Tutor] codecs.open vs io.open

2015-03-03 Thread Mark Lawrence
On 03/03/2015 10:31, Albert-Jan Roskam wrote: Hi, Is there in a (use case) difference between codecs.open and io.open? What is the difference? A small difference that I just discovered is that codecs.open(somefile).read() returns a bytestring if no encoding is specified, but a unicode string i

Re: [Tutor] text file help

2015-03-03 Thread Alan Gauld
On 03/03/15 12:56, Tihomir Zjajic wrote: kl_number = [] myfile = open("formular_doznake.txt") for line in myfile: if line.startswith('1'): num = makeNumber(next[vrs_drv], next[prs_prec], next[teh_kl]) kl_number.append(num) def makeNumber(l1,l2,l3): nums = [] for line in(vr

Re: [Tutor] (no subject)

2015-03-03 Thread Danny Yoo
On Mar 3, 2015 1:49 PM, wrote: > > i expected them to be the same because 10 plus 25 plus 25 divided by 3 is 60 and they both say that but the one that that says total=0. im just not sure how that changes the equation > Please use "reply to all" in your email client. You might be getting confuse

Re: [Tutor] List of ints

2015-03-03 Thread Phil
On 03/03/15 17:46, Mark Lawrence wrote: You are trying to increment the first element of count which is itself a list containing one element. You actually need:- count[0][0] +=1 Thank you Lawrence, Alan, and Danny, The solution is embarrassingly obvious. It's been a long time since I've a

Re: [Tutor] List of ints

2015-03-03 Thread Mark Lawrence
On 03/03/2015 23:09, Phil wrote: On 03/03/15 17:46, Mark Lawrence wrote: You are trying to increment the first element of count which is itself a list containing one element. You actually need:- count[0][0] +=1 Thank you Lawrence, Alan, and Danny, The solution is embarrassingly obvious. I

Re: [Tutor] List of ints

2015-03-03 Thread Steven D'Aprano
On Wed, Mar 04, 2015 at 09:09:03AM +1000, Phil wrote: > I'd been away from home for five weeks and during a quiet period I > installed QPython on my tablet with the aim of porting a programme that > I'd written in C++ 15 years ago to Python. Cutting and pasting and even > moving around the IDE

Re: [Tutor] List of ints

2015-03-03 Thread Steven D'Aprano
On Tue, Mar 03, 2015 at 04:50:41PM +1000, Phil wrote: > count [0] += 1 > > This fails with the following error; > > TypeError: 'int' object is not iterable I know that others have already solved the problem, but here is something which might help you solve similar problems in the future. The