not a big deal or anything, but, curiously:

Jussi Salmela tiedon_jano at hotmail.com
Wed Dec 13 10:12:02 EST 2006


Tim Peters kirjoitti:
> [Simon Schuster]
>> following this tutorial,
> 
> Which tutorial?

He's reading this tutorial which he was already advised not to do:

===========================================
===========================================
===========================================
Simon Schuster wrote:
 > > I'm new to python, and almost new to programming in general. I'm at
 > > http://www.pasteur.fr/formation/infobio/python/ch04.html in that
 > > tutorial, and my 'count' function (if it's called a function?) isn't
 > > working suddenly.
 > >
 >>>> > >>> x = "fljshfjh"
 >>>> > >>> x
 > > 'fljshfjh'
 >>>> > >>> count(x, 'h')
 > > Traceback (most recent call last):
 > >   File "<stdin>", line 1, in ?
 > > NameError: name 'count' is not defined
 > >
 > > I'm not sure what changed, because it used to work. anyhow thanks a 
lot!
 > >

Probably because you omiitted the line

from string import *

However IMHO your use of a tutorial which:

(1) introduces "from some_module import *" as though it is the normal
way of doing things

     From chapter 1: """
     Some magical stuff, that will be explained later:
     >>> from string import *
     """

     That's *bad* magic


(2) is still using (outdated) functions in the string module instead of
teaching string methods

should be discontinued immediately.

You may wish to have a look at some of the /other/ tutorials mentioned
on this page:

http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

HTH,
John

===========================================
===========================================
===========================================


> 
>> I copied and pasted:
>>
>> from string import *
>>
>> cds = """atgagtgaacgtctgagcattaccccgctggggccgtatatcggcgcacaaa
>> tttcgggtgccgacctgacgcgcccgttaagcgataatcagtttgaacagctttaccatgcggtg
>> ctgcgccatcaggtggtgtttctacgcgatcaagctattacgccgcagcagcaacgcgcgctggc
>> ccagcgttttggcgaattgcatattcaccctgtttacccgcatgccgaaggggttgacgagatca
>> tcgtgctggatacccataacgataatccgccagataacgacaactggcataccgatgtgacattt
>> attgaaacgccacccgcaggggcgattctggcagctaaagagttaccttcgaccggcggtgatac
>> gctctggaccagcggtattgcggcctatgaggcgctctctgttcccttccgccagctgctgagtg
>> ggctgcgtgcggagcatgatttccgtaaatcgttcccggaatacaaataccgcaaaaccgaggag
>> gaacatcaacgctggcgcgaggcggtcgcgaaaaacccgccgttgctacatccggtggtgcgaac
>> gcatccggtgagcggtaaacaggcgctgtttgtgaatgaaggctttactacgcgaattgttgatg
>> tgagcgagaaagagagcgaagccttgttaagttttttgtttgcccatatcaccaaaccggagttt
>> caggtgcgctggcgctggcaaccaaatgatattgcgatttgggataaccgcgtgacccagcacta
>> tgccaatgccgattacctgccacagcgacggataatgcatcgggcgacgatccttggggataaac
>> cgttttatcgggcggggtaa""".replace("\n","")
>>
>> gc = float(count(cds, 'g') + count(cds, 'c'))/ len(cds)
>>
>> print gc
>>
>> -fin-
>>
>> which should yield: 0.54460093896713613..
>>
>> but when I ran it I got: 0.544600938967
>>
>> looking now I see it's truncating after a certain number of decimal
>> places. any ideas why?
> 
> Read the Python Tutorial appendix on floating-point issues:
> 
>    http://docs.python.org/tut/node16.html
> 
> As it says, str(a_float) rounds to 12 significant digits, and
> repr(a_float) to 17.  The `print` statement implicitly applies str()
> to each item it prints.

Cheers,
Jussi Salmela



More information about the Python-list mailing list