A bug I found in Python

Andrew Dalke adalke at mindspring.com
Mon Mar 31 02:41:27 CEST 2003


Jp Calderone:
>   Here is an example of this surprising behavior:
>
>       def biffle_buffle_bam(x, y):
>           z = 10
>           print 'Hello world'
>           return anotherFunctionIWrote(x, y)
>
>       print biffle_bam_baffle(10, -10)
>
>   As you can clearly see, when this is run, 0 is printed out!

Uncle Tim:
> Yes, it's clearly a bug in Python.  What's happening is that it saw the 0
in
> "10", and the zero in "-10", and figured 0 was the most popular digit.
As
> is so often the case, Python sacrificed accuracy for popularity.

I think you're simplify things to much.  Both 0 and 1 are equally popular.
The tie-breaking algorithm (which I thought you added?) sees that the 0
is also the most recently used digit.  User studies even back to the ABC
days show that the more recently typed digits are the most readily recalled,
so that choice makes sense.

You can see this if you try the following code

       def biffle_buffle_bam(x, y):
           z = 10
           print 'Hello world'
           return anotherFunctionIWrote(x, y)

       print biffle_bam_baffle(10, -10)

This will print 1, because I typed the '1's *after* I typed the '0's.
Python simply looks at the timestamps for each character to
determine which was typed most recently.

                    Andrew
                    dalke at dalkescientific.com







More information about the Python-list mailing list