Title: Baffling if statement

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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kirk Durston
Sent: Thursday, September 22, 2005 3:35 PM
To: Pythonmac-SIG@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

_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig

Reply via email to