[Pythonmac-SIG] Baffling if statement

Kent Quirk kquirk at solidworks.com
Thu Sep 22 22:05:16 CEST 2005


What are the actual types of temp and Cutoff? Is it possible that you're
not comparing apples to apples?

 

For example, suppose you don't realize that one of your values is a
string?

 

>>> t1="0.19"

>>> t2=0.24

>>> print t1

0.19

>>> print t2

0.24

>>> print t1>t2

True

 

Any possibility that's what's happening?

 

             Kent

 

 

 

________________________________

From: pythonmac-sig-bounces at python.org
[mailto:pythonmac-sig-bounces at python.org] On Behalf Of Kirk Durston
Sent: Thursday, September 22, 2005 3:35 PM
To: Pythonmac-SIG at python.org
Subject: [Pythonmac-SIG] Baffling if statement

 

After spending a couple hours trying to figure out what is going on, I'm
asking for help.

Below is a short segment from a module I've written. Before the part
shown below, temp and Cutoff are defined. then comes the following:

            blank='-'
            if temp>Cutoff:    
                print 'temp is', temp
                print 'cutoff is', Cutoff
                print 'symbol is', symbol
                InfoCollector.append(symbol)
            else:InfoCollector.append(blank)

the print out shows that temp=0.261 and Cutoff is 0.29498. Clearly temp
is smaller than Cutoff, so it should have gone to 'else:' but it didn't.
In fact, no matter if temp is larger or smaller than Cutoff, it always
goes through the 'if' segment.

If I change the sign to '<', then it always goes to the 'else'
regardless of the values of temp and Cutoff and never goes through the
'if' segment.

When I write a short program to try to duplicate the problem everything
works normally.

Baffled,

Kirk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/pythonmac-sig/attachments/20050922/1db061fc/attachment-0001.htm


More information about the Pythonmac-SIG mailing list