Hi all - first off, I apologize in advance for being a novice. Any help would be greatly appreciated.
I'm a graduate student in psychology trying out a new programming language for my experiments. I'm going to be using PyEPL which is based on Python. Coming from AppleScript (and having very little programming experience overall), I'm a little overwhelmed trying to get my first experiment to work. Fortunately, what I need doesn't seem like it should be all that complicated. I just need to start thinking in Python.
Basically, I need to read in a text file, which is composed of 3 columns, the first of which contains a cue word; the second a response word, while the third column contains a dummy code letting the program know how to present the word pair (e.g., present the string in [R]ED or [G]REEN). The experiment will run through each line of text one at a time (i.e., each line is one trial).
So the structure might look like this:
CAT, MEOW, r
TABLE, CHAIR, g
SHOE, SOCK, r
In the end, I'd want to print "CAT-MEOW" in red (specified by the 'r') and TABLE-CHAIR in green.
I was then thinking it would be best to break up each line into a tuple, so I could say something along the lines of...:
Basically, I am wondering how to get it to set the color of the cue and response words for each tuple within data. Specifically, I'm not sure how to get it to iterate through each sub-tuple (i.e., each line) in the now combined tuple) or how to set the font color dependent on the 3rd element in each.
About my system:
Mac OSX 10.4, English
Python 2.4.4 (#1, Oct 18 2006, 10:34:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Once again, thank you in advance,
Justin
I'm a graduate student in psychology trying out a new programming language for my experiments. I'm going to be using PyEPL which is based on Python. Coming from AppleScript (and having very little programming experience overall), I'm a little overwhelmed trying to get my first experiment to work. Fortunately, what I need doesn't seem like it should be all that complicated. I just need to start thinking in Python.
Basically, I need to read in a text file, which is composed of 3 columns, the first of which contains a cue word; the second a response word, while the third column contains a dummy code letting the program know how to present the word pair (e.g., present the string in [R]ED or [G]REEN). The experiment will run through each line of text one at a time (i.e., each line is one trial).
So the structure might look like this:
CAT, MEOW, r
TABLE, CHAIR, g
SHOE, SOCK, r
In the end, I'd want to print "CAT-MEOW" in red (specified by the 'r') and TABLE-CHAIR in green.
I was then thinking it would be best to break up each line into a tuple, so I could say something along the lines of...:
Code:
from string import strip input = open('Desktop/TNTtest/input_test_comma.txt') data = [] for line in input: data.append (tuple (map(strip, line.split(',',1)))) s = data[0][0] + "-" + data[0][1] if data[0][2] == "r": print "<font color='RED'> s </FONT>" elif data[0][2] == "g": print "<font color='GREEN'> s </FONT>"
About my system:
Mac OSX 10.4, English
Python 2.4.4 (#1, Oct 18 2006, 10:34:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Once again, thank you in advance,
Justin
Comment