Eprime outputs a .txt file like this:
*** Header Start *** VersionPersist: 1 LevelName: Session Subject: 7 Session: 1 RandomSeed: -1983293234 Group: 1 Display.RefreshRate: 59.654 *** Header End *** Level: 2 *** LogFrame Start *** MeansEffectBias: 7 Procedure: trialProc itemID: 7 bias1Answer: 1 *** LogFrame End *** Level: 2 *** LogFrame Start *** MeansEffectBias: 2 Procedure: trialProc itemID: 2 bias1Answer: 0
I want to parse this and write it to a .csv file but with a number of lines deleted.
I tried to create a dictionary that took the text appearing before the colon as the key and the text after as the value:
{subject: [7, 7], bias1Answer : [1, 0], itemID: [7, 2]}
def load_data(filename): data = {} eprime = open(filename, 'r') for line in eprime: rows = re.sub('\s+', ' ', line).strip().split(':') try: data[rows[0]] += rows[1] except KeyError: data[rows[0]] = rows[1] eprime.close() return data
for line in open(fileName, 'r'): if ':' in line: row = line.strip().split(':') fullDict[row[0]] = row[1] print fullDict
both of the scripts below produce garbage:
{'\x00\t\x00M\x00e\x00a\x00n\x00s\x00E\x00f\x00f\x00e\x00c\x00t\x00B\x00i\x00a\x00s\x00': '\x00 \x005\x00\r\x00', '\x00\t\x00B\x00i\x00a\x00s\x002\x00Q\x00.\x00D\x00u\x00r\x00a\x00t\x00i\x00o\x00n\x00E\x00r\x00r\x00o\x00r\x00': '\x00 \x00-\x009\x009\x009\x009\x009\x009\x00\r\x00'
If I could set up the dictionary, I can write it to a csv file that would look like this!!:
Subject itemID ... bias1Answer 7 7 1 7 2 0