LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 03-18-2004, 09: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, 10: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



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

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

All times are GMT -5. The time now is 08:38 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