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 03-18-2004, 09:26 AM   #1
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}, '': '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}, '': [-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.


# import MySQL module
import MySQLdb
from rpy import *

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

# create a cursor

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

# get the resultset as a tuple

# 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
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']


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 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 > Forums > Non-*NIX Forums > Programming

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

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