LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 04-14-2004, 02:19 PM   #1
SerfurJ
Member
 
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.

Code:
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",
db="2d-gels")

cursor=db.cursor()

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

    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]]])

    pvalues.sort()

    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" % 
value[6]
        else:
            print "failed"

analysis(1)
analysis(2)
i'd appreciate any suggestions. i'm at a dead end here.

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

Rep: Reputation: 32
Like this friend:

Code:
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, 02:58 PM   #3
SerfurJ
Member
 
Registered: May 2003
Posts: 80

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


Reply



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 04:24 PM
CGI in Python indian Programming 2 08-18-2004 02:32 PM
Bizarre KDE behavior as root lava135 Linux - Newbie 4 09-04-2003 03:18 PM
Help! Bizarre behavior on smbfs mounted NTFS drive jkcunningham Linux - Networking 0 08-06-2003 05:17 PM
CGI Variables cleared by SuSEfirewall2 fwalthard Linux - Networking 1 06-26-2003 12:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:35 PM.

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