Re: [Tutor] __abs__() not acting as expected

2014-03-23 Thread Ben Finney
Dave Angel writes: > Ben is right, dunder methods don't belong in introductory texts. […] > But he didn't show you the simplest fix: > > (-3).__abs__() I disagree; the simplest fix is not to call that method directly, and just use:: abs(-3) -- \ “Computer perspective on Moore'

Re: [Tutor] __abs__() not acting as expected

2014-03-23 Thread Dave Angel
Jim Byrnes Wrote in message: > I am reading Practical Programming - An Introduction to Computer Science > Using Python 3. They give this example: > > >>> abs(-3) > 3 > > >>> -3 .__abs__() > 3 > Ben is right, dunder methods don't belong in introductory texts. And they seldom should be ca

[Tutor] Expressions, literals, operator precedence (was: __abs__() not acting as expected)

2014-03-23 Thread Ben Finney
Jim Byrnes writes: > I am reading Practical Programming - An Introduction to Computer > Science Using Python 3. They give this example: > > >>> abs(-3) > 3 > > >>> -3 .__abs__() > 3 That's a poor example, in my opinion. It's not good for an introductory text to show calling dunder methods like

[Tutor] __abs__() not acting as expected

2014-03-23 Thread Jim Byrnes
I am reading Practical Programming - An Introduction to Computer Science Using Python 3. They give this example: >>> abs(-3) 3 >>> -3 .__abs__() 3 When I try it in idle or a terminal I get different results. Python 3.3.5 (default, Mar 12 2014, 02:09:17) [GCC 4.6.3] on linux >>> abs(-3) 3 >

Re: [Tutor] character counting

2014-03-23 Thread Cameron Simpson
On 23Mar2014 17:28, Mustafa Musameh wrote: > Hi; > I have a file that looks like this: > >title 1 > AAATTTGGGCCCATA... > TTAACAAGTTAAAT > >title 2 > AAATTTAAACCC > ATATATATA > > > I wrote the following to count the As, Cs, Gs anTs for each title I wrote the > following > > import sys > > f

Re: [Tutor] character counting

2014-03-23 Thread Alan Gauld
On 23/03/14 06:28, Mustafa Musameh wrote: Hi; I have a file that looks like this: >title 1 AAATTTGGGCCCATA... TTAACAAGTTAAAT… >title 2 AAATTTAAACCC… ATATATATA… … I want to get the following out put: >title 234 >title 1 3453 …. Your example data and example output don't match - at

Re: [Tutor] character counting

2014-03-23 Thread spir
On 03/23/2014 07:28 AM, Mustafa Musameh wrote: Hi; I have a file that looks like this: title 1 AAATTTGGGCCCATA... TTAACAAGTTAAAT… title 2 AAATTTAAACCC… ATATATATA… … I wrote the following to count the As, Cs, Gs anTs for each title I wrote the following import sys file = open('file.fna'

[Tutor] character counting

2014-03-23 Thread Mustafa Musameh
Hi; I have a file that looks like this: >title 1 AAATTTGGGCCCATA... TTAACAAGTTAAAT… >title 2 AAATTTAAACCC… ATATATATA… … I wrote the following to count the As, Cs, Gs anTs for each title I wrote the following import sys file = open('file.fna') data=file.readlines() for line in data: li