LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 03-18-2004, 10:26 AM   #1
SerfurJ
Member
 
Registered: May 2003
Posts: 80

Rep: Reputation: 15
newbie python question: doing more than one thing in a for loop


i'm using the rpy module to interface the R statistics language.
the first print line (with the "-" before it) at the bottom
of the script gives ~500 of the following:

{'null.value': {'difference in means': 0.0}, 'data.name': 'c(0.007,
0.007, 0.135) and c(0.072, 0.003, 0.033)', 'method': 'Welch Two
Sample t-test', 'p.value': 0.79164656667870525, 'statistic': {'t':
0.29009514644766238}, 'estimate': {'mean of y': 0.035999999999999997,
'mean of x': 0.049666666666666671}, 'conf.int': [-0.14127029902675267,
0.16860363236008602], 'parameter': {'df': 2.8365235114711265},
'alternative': 'two.sided'}

i want to add the lines with the "+" to extract the p.value from the
dictionary data type above, while in the loop.



#!/usr/bin/python

# import MySQL module
import MySQLdb
from rpy import *

# connect
db=MySQLdb.connect(host="localhost", user="xxx", passwd="xxx",
db="2d-gels")

# create a cursor
cursor=db.cursor()

# execute SQL statement
cursor.execute("SELECT * FROM `022704`")

# get the resultset as a tuple
result=cursor.fetchall()

# iterate through resultset
for record in result:
- print r.t_test(record[0:4],record[4:8])

+ fulldata = r.t_test(record[0:4],record[4:8])
+ print fulldata['p.value']
 
Old 03-18-2004, 11:14 AM   #2
SerfurJ
Member
 
Registered: May 2003
Posts: 80

Original Poster
Rep: Reputation: 15
here is the solution:

fulldata = r.t_test(record[0:4],record[4:8]); print fulldata['p.value']
 
  


Reply


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
C++ FOR loop issues -- C++ Newbie Please Help BenRichards Programming 2 02-22-2005 04:17 PM
Another ? from a newbie - stuck in a while loop azucarmom Programming 2 12-05-2004 09:41 PM
python call function in same file(very newbie question) rmanocha Programming 2 11-21-2004 01:04 AM
Simple while loop problem (newbie question) Seventh Programming 3 09-07-2004 01:00 PM
Python - Set vars and loop over lines in file jnoller Programming 6 02-07-2004 11:32 AM


All times are GMT -5. The time now is 07:54 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration