Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 04-14-2004, 03:19 PM   #1
Registered: May 2003
Posts: 80

Rep: Reputation: 15
Exclamation bizarre python behavior - simple cgi variables

when p_value is assigned to 0.01, the "if" statement near the bottom of the program acknowledges it and the program only prints the results with a p_value of < 0.01.

when p_value is assigned to form['pvalue_number'].value, which is equal to 0.01 (verified by print), it's as if the "for" loop completely ignores the "if" statement.

i've done a lot of debugging and concluded that the if clause does not evaluate to false and the for loop runs the code without exiting. all relevant variables have been verified by printing them.

lengthy irrelevant parts of the program have been cut out to improve readability.

from rpy import *
import MySQLdb, cgi
import cgitb; cgitb.enable()

print "Content-Type: text/html\n\n"
print "<pre>"

form = cgi.FieldStorage()
exp_date = form['exp_date'].value
p_value = 0.01
#p_value = form['pvalue_number'].value
print form['pvalue_number'].value

general_conditions = # ... snip
conditions = # ... snip
fields = # ... snip

query = 'SELECT %s FROM `%s_allGels` LEFT JOIN `%s_statistics` \nUSING ( NUMBER ) 
%s \nGROUP BY `ctrl4 ID`'

db=MySQLdb.connect(host="localhost", user="xxxx", passwd="xxxx",


def analysis(n):    
    cursor.execute(query % (fields, exp_date, exp_date, conditions[n]))

    pvalues = []
    for dataslice in data:
        fullstats = r.t_test(dataslice[0:4],dataslice[4:8])
        pvalues.extend([[fullstats['p.value'], dataslice[8], dataslice[9], dataslice[10], 
dataslice[11], dataslice[12], dataslice[13]]])


    for value in pvalues:
        if value[0] < p_value:
            print "%5d" % value[1], "  %8f" % float(value[0]), "  %5.3f" % 
value[2], "   %5.2f" % value[3], "    %5.3f" % value[4], "  %5.2f" % value[5], "   %6.3f" % 
            print "failed"

i'd appreciate any suggestions. i'm at a dead end here.

Last edited by SerfurJ; 12-19-2004 at 10:50 AM.
Old 04-14-2004, 03:53 PM   #2
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
Like this friend:

if float(value[0]) < float(p_value)
I don't think I am mistaken when I say you are trying to compare a string and a floating point intager.

Hope that works!
Old 04-14-2004, 03:58 PM   #3
Registered: May 2003
Posts: 80

Original Poster
Rep: Reputation: 15
man, so simple. well that did it. thanks a lot.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python CGI - Batching in R larsenmtl Programming 1 09-29-2004 05:24 PM
CGI in Python indian Programming 2 08-18-2004 03:32 PM
Bizarre KDE behavior as root lava135 Linux - Newbie 4 09-04-2003 04:18 PM
Help! Bizarre behavior on smbfs mounted NTFS drive jkcunningham Linux - Networking 0 08-06-2003 06:17 PM
CGI Variables cleared by SuSEfirewall2 fwalthard Linux - Networking 1 06-26-2003 01:33 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:00 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration